Definition and Usage
The setUTCFullYear() method is used to set the year according to Universal Time (UTC).
Syntax
dateObject.setUTCFullYear(year,month,day)
Parameters | Description |
year | Required. The value of the year field to set for the dateObject. This parameter should be the complete year with century value, such as 1999, not just the abbreviated year value, such as 99. |
month | Optional. The value of the month field to set for the dateObject. Expressed using world time. This parameter is an integer between 0 ~ 11. |
day | Optional. The value of the day field to be set for dateObject. Expressed using world time. This parameter is an integer between 1 ~ 31. |
Return value
Adjusted date expressed in milliseconds
Tips and comments:
Comments : 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
Example 1
In this example, we will set the year to 1992 through the setUTCFulYear() method:
<script type="text/javascript"> var d = new Date() d.setUTCFullYear(1992) document.write(d) </script>
Output:
Sat Nov 07 1992 14:21:20 GMT+0800 (中国标准时间)
Example 2
In this example, I will set the date to November 3, 1992 through the setUTCFulYear() method:
<script type="text/javascript"> var d = new Date() d.setUTCFullYear(1992,10,3) document.write(d) </script>
Output:
Tue Nov 03 1992 14:21:20 GMT+0800 (中国标准时间)
If the monthValue and dayValue parameters are not specified, the values returned from the getMonth and getDate methods are used. If the specified parameters are outside the expected range, call setUTCFullYear to try to update other parameters and the corresponding date information of the Date object. For example, if you specify 15 for monthValue, the year is in increments of 1 (year + 1), and 3 is used to represent the month.
Example:
<html> <head> <title>JavaScript setUTCFullYear Method</title> </head> <body> <script type="text/javascript"> var dt = new Date( "Aug 28, 2008 23:30:00" ); dt.setUTCFullYear( 2006 ); document.write( dt ); </script> </body> </html>
This will produce the following results:
Mon Aug 28 23:30:00 UTC+0530 2006
The above is the detailed content of JavaScript method setUTCFulYear() to set the year according to Universal Time (UTC). For more information, please follow other related articles on the PHP Chinese website!