Home > Article > Web Front-end > JavaScript method setFullYear() for setting the year
Definition and Usage
The setFullYear() method is used to set the year.
Syntax
dateObject.setFullYear(year,month,day)
Parameters | Description |
year | Required. A four-digit integer representing the year. Expressed in local time. |
month | Optional. A numerical value representing the month, between 0 and 11. Expressed in local time. |
day | Optional. Represents the value of a certain day of the month, between 1 and 31. Expressed in local time. |
Return Value
Returns the millisecond representation of the adjusted date.
Tips and Comments:
Comments: This method is always used in conjunction with a Date object.
Example
Example 1
In this example, we will set the year to 1992 through setFullYear():
<script type="text/javascript"> var d = new Date() d.setFullYear(1992) document.write(d) </script>
Output:
Sat Nov 07 1992 11:35:49 GMT+0800 (中国标准时间)
Example 2
In this example, we will set the date to November 3, 1992 via setFullYear():
<script type="text/javascript"> var d = new Date() d.setFullYear(1992,10,3) document.write(d) </script>
Output:
Tue Nov 03 1992 11:35:49 GMT+0800 (中国标准时间)
Example:
<html> <head> <title>JavaScript setFullYear Method</title> </head> <body> <script type="text/javascript"> var dt = new Date( "Aug 28, 2008 23:30:00" ); dt.setFullYear( 2000 ); document.write( dt ); </script> </body> </html>
This will produce the following results:
Mon Aug 28 23:30:00 UTC+0530 2000
The above is the detailed content of JavaScript method setFullYear() for setting the year. For more information, please follow other related articles on the PHP Chinese website!