Working with time
Along with the date components, the Date object stores time information as well. The following methods provide access to a Date object's time information:
- getHours Returns the hour portion of the time.
- getMinutes Returns the minutes portion of the time.
- getSeconds Returns the seconds portion of the time.
- getMilliseconds Returns the milliseconds portion of the time.
- getTime Returns the number of milliseconds since midnight January 1, 1970.
- getTimezoneOffset Returns the difference in minutes between local time and Greenwich Mean Time (GMT).
- getUTCHours Returns the hour portion of the time according to UTC.
- getUTCMinutes Returns the minutes portion of the time according to UTC.
- getUTCSeconds Returns the seconds portion of the time according to UTC.
- getUTCMilliseconds Returns the milliseconds portion of the time according to UTC.
<script language="javascript"> var d = new Date(); document.write(d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ":" + d.getMilliseconds()); document.write(d.getTime()); </script>It displays the following output:
12:36:33:41 1146760593041The second value is a bit odd since it displays the number of milliseconds since January 1, 1970 to the value stored in the referenced Date object. It comes in handy when finding the difference between two values. As with date values, a setTime method is available as well:
Var dt1 = new Date(); var dt2 = new Date(1970, 4, 15); dt1.setTime(dt2.getTime());Setting properties
Like the setTime, setDate, and setMilliseconds methods, there are methods to populate all portions of a Date object. This includes the following:
- setFullYear
- setHours
- setMinutes
- setMilliseconds
- setMonth
- setSeconds
- setUTCFullYear
- setUTCMonth
- setUTCHours
- setUTCSeconds
- setUTCMilliseconds
Do you need help with Web Technologies? 



1
Sudip Dey - 05/03/08
codes are simple to understand....also give code which autorefresh the time....
I need your comments also....
» Report offensive content
2
Linda - 01/10/08
As part of my job, I add an expiration date to secured spec. The date is to be 1 week from the day someone prints or opens a specific spec. My problem is that it only works on 98 computers and not XP. I inherited the code and am not too familar with JavaScrip. Can you tell me why this does not work on XP computers?
Thanks for you time.
» Report offensive content