JavaScript Date Object Time functions

by top54u.com 20 Mar, 2008

JavaScript Date Object also provides the functions to get the parts of current time. To get the Time parts such as hours, minutes, seconds and milliseconds you can define a variable for Date Object using new keyword. This will provide all the methods for retrieving the parts of the Time as well as Date, from which you can use Time related functions to work upon.

 

 

JavaScript Date Object Methods to retrieve the Time Parts:

 

getHours()
getHours
function returns the current Hour of Time retrieved using Date Object range from 0 to 23.

 

getMinutes()
getMinutes
function returns the current minute of Time retrieved using Date Object range from 0 to 59.

 

getSeconds()
getSeconds
function returns the current second of Time retrieved using Date Object range from 0 to 59.

 

getMilliseconds()
getMilliseconds
function returns the milli seconds of Time retrieved using Date Object range from 0-999.

 

getTimezoneOffset()
getTimezoneOffset
returns the difference between current local time and Greenwich Mean Time in minutes.

 

 

JavaScript code Example to retrieve Time Parts using Date Object:

 

// Date object defined with new keyword.
var myDate = new Date();

 

// JavaScript getHours Function
document.write(myDate.getHours());

 

// JavaScript getMinutes Function
document.write(myDate.getMinutes());

 

// JavaScript getSeconds Function
document.write(myDate.getSeconds());

 

// JavaScript getMilliseconds Function
document.write(myDate.getMilliseconds());

 

// JavaScript getTimezoneOffset Function
document.write(myDate.getTimezoneOffset());

 

You can divide the getTimezoneOffset with 60 to get the GMT difference in hours. It will return the hours in +/- according to your country.

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:18:41 AM




related videos.....
recent posts.....
top54u ezines.....