Skip to content
Advertisements

JavaScript Date.setMilliseconds()

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

Chromeyes
Edgeyes
Firefox1
Internet Exploreryes
Operayes
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: