Java Reference
In-Depth Information
To illustrate this, compare Figure 7-1 to Figure 7-2, where the date on the computer's clock has been
advanced to December, which is in the winter when daylight savings is not in effect.
FiGure 7-2  
The next two methods are toLocaleTimeString() and toTimeString() , as follows:
html += "<p>Using toLocalTimeString() gives: " +
localTime.toLocaleTimeString() + "</p>";
html += "<p>Using toTimeString() gives: " +
localTime.toTimeString() + "</p>";
These methods display just the time part of the date and time held in the Date object. The
toLocaleTimeString() method displays the time as specified by the user on his computer. The second
method displays the time but also gives an indication of the time zone (in the example, EST for Eastern
Standard Time in America).
The final two methods display the date part of the date and time. The toLocaleDateString() displays
the date in the format the user has specified on his computer. On Windows operating systems, this is set
in the regional settings of the PC's Control Panel. However, because it relies on the user's PC setup, the
look of the date varies from computer to computer. The toDateString() method displays the current
date contained in the PC date in a standard format.
Of course, this example relies on the fact that the user's clock is set correctly, not something you can be
100 percent sure of—it's amazing how many users have their local time zone settings set completely wrong.
setting and Getting a date object's utC date and time
When you create a new Date object, you can either initialize it with a value or let JavaScript set
it to the current date and time. Either way, JavaScript assumes you are setting the local time
 
Search WWH ::




Custom Search