JavaScript Date setMilliseconds() Method

Definition and Usage

setMilliseconds() Method to set the milliseconds of a date object.

Example

Set milliseconds to 192:

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

Try It Yourself

Syntax

Date.setMilliseconds(millisec)

Parameter Value

Parameter Description
millisec

Required. An integer representing milliseconds.

The expected value is 0-999, but other values are allowed:

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

Technical Details

Return Value: A number representing the milliseconds between the date object and midnight on January 1, 1970.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
setMilliseconds() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Date Setting Methods