Using the Date() Object to Create a Clock - So, what is the time?
(Page 2 of 4 )
Two other aspects that should be noted here are the Date object's ability to display UTC or Coordinated Universal Time and also GMT or Greenwich Mean Time. This UTC value is measured in milliseconds since January 1, 1970, from midnight. This behavior exists on all OS platforms and is therefore universally accepted through the JavaScript code. Where the year is concerned, getFullYear() assists with the correct format by using four digits to avoid dates before 2000 becoming inaccurate. The year 1997 would need to be entered as 1997 and not 97, which uses only the last two digits.
Another point to note here is what happens during the interpretation by JavaScript. Bear in mind that 280 seconds is interpreted as 4 minutes and 40 seconds. The Macromedia flash player and other applications all utilize the Date object's properties to extract the time and date from the operating system, whether it is a MAC or Windows platform. There are a couple of slight differences here between the operating systems on a MAC and a PC. There is the absence of a time zone database on MAC OS systems 8 and 9, so DST or Daylight Saving Time is not reported correctly. This has been corrected on MAC OS X systems. On Windows systems on PCs, the DST adjustment is made automatically.
Why is it that the human psyche is so obsessed with time anyway, causing programmers to have to cater to this need? It is good for web sites that the Date object was created. People spend so much time on their computers these days, whether it is for work purposes or just pure recreation. Being date and time conscious helps one realize what time it is on a regular basis. It is always there in the bottom right corner in the systems tray on Windows OS systems.
Now, on web pages, it has become ubiquitous as more and more designers want to utilize the Date object to let their visitors know the time. Days can be complex. A meeting may be scheduled; a birthday needs to be planned; is it time to leave work yet and go home and relax? Of course, it cannot be forgotten how important it is not to miss an episode of "Lost" or "24" due to being plugged into the computer monitor. The Date object applies to our constant need for information throughout the day.
There are other methods that utilize the Date() object, but for this article, a walk through of how to manipulate the object to produce some clock and date formats will be explored.
Next: A Live Clock Example >>
More JavaScript Articles
More By Stephen Davies