Time within day (Time calculation)

A date and time algorithm.

Availability:

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

Calculating the time within a day uses modulo arithmetic to find the remainder after calculating the day number.

The formula for calculating time within the day is shown here:

Example code:

   // Define some constants
   HoursPerDay      =   24;
   MinutesPerHour   =   60;
   SecondsPerMinute =   60;
   msPerSecond      = 1000;
   
   // Derived values
   msPerMinute = msPerSecond * SecondsPerMinute;
   msPerHour   = msPerMinute * MinutesPerHour;
   msPerDay    = msPerHour   * HoursPerDay;
   
   // Grab the time now in milliseconds
   myMilliseconds = Number(new Date());
   document.write("Time within day ...: ");
   document.write(TimeWithinDay(myMilliseconds));
   document.write("<BR>");
   
   // Work out the millisecond time value
   function TimeWithinDay(aMillisecondTime)
   {
      return (aMillisecondTime % msPerDay);
   }

See also:Broken down time, Day number, Time from year, Time range

Cross-references:

ECMA 262 edition 2 - section - 15.9.1.2

ECMA 262 edition 3 - section - 15.9.1.2