Why setMilliseconds ?
The JavaScript Date setMilliseconds () method is a built-in function. sets milliseconds for a specific date by local time.
Syntax:
Date.setMilliseconds(millisecondsValue)
- millisecondsValue :Represents milliseconds. Gets values from 0 to 999.
- If you specify a number outside the expected range, the date information in the Date object is updated accordingly. For example, if you specify 1010, the number of seconds is incremented by 1, and 10 is used for the milliseconds.
JavaScript setMilliseconds Examples
Example 1
The setMilliseconds () method can change the millisecond value of a given date.
var date = new Date('April 21, 1983 22:47:55:132');
console.log(date.getMilliseconds());
date.setMilliseconds(554);
console.log(date.getMilliseconds())
132
554
Example 2
The setMilliseconds () method can change the millisecond value of the current time.
var now = new Date();
console.log(now.getMilliseconds());
date.setMilliseconds(254);
console.log(date.getMilliseconds())
887
254
Example 3
- If you specify a number outside the expected range, the date information in the Date object is updated accordingly. For example, if you specify 1010, the number of seconds is incremented by 1, and 10 is used for the milliseconds.
var date = new Date('April 21, 1983 13:22:32:77');
console.log(date.getMilliseconds());
date.setMilliseconds(2004);
console.log(date.getMilliseconds())
77
4
Browser Support
| Chrome | yes |
| Edge | yes |
| Firefox | 1 |
| Internet Explorer | yes |
| Opera | yes |
| Safari | yes |
| Android webview | yes |
| Chrome for Android | yes |
| Edge mobile | yes |
| Firefox for Android | 4 |
| Opera Android | yes |
Leave a comment