|
October 22, 1999 Implementing Relative Times Tips: October 1999
Yehuda Shiran, Ph.D.
|
|
Let's use the Date object to compute the day and the date of an event, using the time difference between the event and the current date. Suppose you want to know the date 99 days ago. Since the time difference is computed in milliseconds, you need to subtract 99 * 24 * 60 * 60 * 1000 milliseconds from the current time. The current time is expressed as the number of milliseconds since January 1, 1970. The following script computes the day and the date 99 days ago:
Notice that Sunday is the first day of the week and its index is 0. Similarly, the first month of the year is January and its numeric value is 0 as well. Also be sure to notice the Y2K solution in the script.
People who read this tip also read these tips: Look for similar tips by subject: |