This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

setTime

Summary

Sets the date and time value in the Date object.

Syntax

dateObj.setTime( milliseconds )
dateObj
Required. Any Date object.
milliseconds
Required. A numeric value representing the number of elapsed milliseconds since midnight, January 1, 1970 GMT.

Examples

The following example illustrates the use of the setTime method.

function SetTimeTest(newtime){
    var d, s;                  //Declare variables.
    d = new Date();            //Create Date object.d.setTime( newtime ) ;        //Set time.
    s = "Current setting is ";
    s += d.toUTCString();
    return(s);                 //Return new setting.
 }

Remarks

If milliseconds is negative, it indicates a date before 1970. The range of available dates is approximately 285,616 years from either side of 1970.

Setting the date and time with the setTime method is independent of the time zone.

See also

Other articles

Attributions

  • Microsoft Developer Network: Article