Javascript - Date setUTCMilliseconds() Method

The setUTCMilliseconds() method sets the milliseconds between 0 to 999, according to universal time.

Description

The setUTCMilliseconds() method sets the milliseconds between 0 to 999, according to universal time.

UTC time is the same as GMT time.

Syntax

Date.setUTCMilliseconds(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, according to UTC time:

Demo

//display the UTC milliseconds of a date time, after setting the UTC milliseconds.
var d = new Date();
d.setUTCMilliseconds(192);//from  ww  w. j  a  v a  2 s . c  o m
var n = d.getUTCMilliseconds();
console.log(n);

Result