Home > Article > Web Front-end > JavaScript method setUTCMilliseconds() to set the milliseconds of a specified time based on Universal Time (UTC)
Definition and Usage
The setUTCMilliseconds() method is used to set the milliseconds of the specified time based on Universal Time (UTC).
Syntax
dateObject.setUTCMilliseconds(millisec)
Parameters | Description |
millisec | Required. The value of the milliseconds field to set for the dateObject. Expressed using world time. This parameter is an integer between 0 ~ 999. |
Return value
Adjusted date expressed in milliseconds.
Tips and Notes:
Note: If one of the above parameters is specified using a one-digit number, then JavaScript will be included in the result Add one or two leading zeros.
Note: This method is always used in conjunction with a Date object.
Tip: For more information about Universal Coordinated Time (UTC), please refer to Baidu Encyclopedia.
Example
In this example, we will set the millisecond field of the current time to 001 through the setUTCMilliseconds() method:
<script type="text/javascript"> var d = new Date() d.setUTCMilliseconds(1) document.write(d) </script>
Output:
Wed Nov 08 2017 10:01:53 GMT+0800 (中国标准时间)
If the specified parameter is outside the expected range, setUTCMilliseconds attempts to update the latest information of the Date object accordingly. For example, if millisecondsValue uses 1100, the seconds stored in the date object will be increased by 1, and 100 will be used for milliseconds.
Example:
<html> <head> <title>JavaScript setUTCMilliseconds Method</title> </head> <body> <script type="text/javascript"> var dt = new Date( "Aug 28, 2008 23:30:00" ); dt.setUTCMilliseconds( 1100 ); document.write( dt ); </script> </body> </html>
This will produce the following results:
Thu Aug 28 23:30:01 UTC+0530 2008
The above is the detailed content of JavaScript method setUTCMilliseconds() to set the milliseconds of a specified time based on Universal Time (UTC). For more information, please follow other related articles on the PHP Chinese website!