Javascript - Date setMilliseconds() Method

The setMilliseconds() method sets the milliseconds of a date object.

Description

The setMilliseconds() method sets the milliseconds of a date object.

Syntax

Date.setMilliseconds(millisec)

Parameter Values

Parameter Require Description
millisec Required. An integer representing the milliseconds

For the millisec value, the expected values are 0-999, but other values are allowed:

  • -1 will result in the last millisecond of the previous second
  • 1000 will result in the first millisecond of the next second
  • 1001 will result in the second millisecond of the next second

Return

A Number, representing the number of milliseconds between the date object and midnight January 1 1970

Example

Set the milliseconds to 192:

Demo

//display the millisecond of a date time, after setting the millisecond.
var d = new Date();
d.setMilliseconds(192);//from   w w w.j av a 2 s . c o  m
var n = d.getMilliseconds();
console.log(n);

Result