Definition and Usage
The setUTCDate() method is used to set a day of the month based on Universal Time (UTC).
Syntax
dateObject.setUTCDate(day)
Parameters | Description |
day | A certain day in , expressed in universal time. This parameter is an integer between 1 ~ 31. |
Return value
Adjusted date expressed in milliseconds.
Tips and Notes:
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 day field of the current month to 15 through the setUTCDate() method:
<script type="text/javascript"> var d = new Date() d.setUTCDate(15) document.write(d) </script>
Output:
Wed Nov 15 2017 14:11:35 GMT+0800 (中国标准时间)
If the specified parameter is outside the expected range, calling setUTCDate attempts to update the latest information of the Date object accordingly.
Example:
<html> <head> <title>JavaScript setUTCDate Method</title> </head> <body> <script type="text/javascript"> var dt = new Date( "Aug 28, 2008 23:30:00" ); dt.setUTCDate( 20 ); document.write( dt ); </script> </body> </html>
This will produce the following results:
Wed Aug 20 23:30:00 UTC+0530 2008
The above is the detailed content of The JavaScript method setUTCDate() sets the day of the month according to Universal Time (UTC). For more information, please follow other related articles on the PHP Chinese website!