Day number (Time calculation)

A date and time algorithm.

Availability:

ECMAScript edition - 2
Property/method value type:Number primitive

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)

Example code:

   // 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;

   }

See also:Broken down time, Date from time, Date number, Day within year, Month from time, Month number, Time from year, Time range, Time within day, Week day

Cross-references:

ECMA 262 edition 2 - section - 15.9.1.2

ECMA 262 edition 3 - section - 15.9.1.2