Calculating day numbers uses the `Math.floor()` function. It is the largest integer remaining after the time value is divided by the number of milliseconds per day.

The formula for calculating day number is shown here:

t = an instant in time measured in milliseconds relative to 01-January-1970 UTC.

`msPerDay = 86400000`

`Day(t) = Math.floor(t/msPerDay)`

// Measure time in milliseconds since 01-01-1970 and work // out the day number var myDate = Number(new Date()); document.write(dayNumber(myDate)); // Work out day number from milliseconds function dayNumber(aMillisecondTime) { var msPerDay = 86400000 var myDay = Math.floor(aMillisecondTime/msPerDay); return myDay; }

Prev | Home | Next |

Day from year | Up | Day within year |

JavaScript Programmer's Reference, Cliff WoottonWrox Press (www.wrox.com)Join the Wrox JavaScript forum at p2p.wrox.comPlease report problems to support@wrox.com© 2001 Wrox Press. All Rights Reserved. Terms and conditions. |