HTML and CSS Reference
In-Depth Information
EXAMPLE 9.17 ( CONTINUED )
document.write("The full year is " + year +"<br />");
document.write("<b>The time is:</b> " +
hours + ":" + minutes + ":" + seconds );
</script>
</big>
</body>
</html>
EXPLANATION
1
A new Date object called now is created. It contains a string with the current date
and time: Mon Aug 10 18:22:36 GMT-0700(Pacific Daylight Time).
2
The variable called hours is assigned the return value of the getHours() method.
3
The variable called minutes is assigned the return value of the getMinutes() method.
4
The variable called seconds is assigned the return value of the getSeconds() method.
5
The variable called year is assigned the return value of the getFullYear() method,
2010 . The output is shown in Figure 9.21.
Figure 9.21 Date object and its methods.
9.4.2 Manipulating the Date and Time
JavaScript stores dates in milliseconds, so if you have more complicated calculations to
perform, such as the number of days before a date, or between two dates, the informa-
tion in Table 9.4 might be helpful in converting milliseconds to minutes, hours, days,
and so forth.
 
 
Search WWH ::




Custom Search