JavaScript setMilliseconds()Method

Date 对象参考手册JavaScript Date Object

Example

Set the milliseconds field of the specified time to 192:

var d = new Date();
d.setMilliseconds(192);
var n = d.getMilliseconds();

nOutput:


Try it yourself »

Definition and Usage

The setMilliseconds() method is used to set the milliseconds field of the specified time.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setMilliseconds() method


Syntax

Date.setMilliseconds(millisec)

Parameter Values

Parameter Description
millisec Required. Used to set the milliseconds field of the dateObject.

This parameter is an integer between 0 and 999:

  • -1 is the last millisecond of the previous second
  • 1000 is the first millisecond of the next second
  • 1001 is the second millisecond of the next second

Return Value

Type Description
Number The millisecond representation from midnight January 1, 1970 to the adjusted date.

Technical Details

JavaScript Version: 1.3


Date 对象参考手册JavaScript Date Object

Other Extensions