Home >Web Front-end >JS Tutorial >Introduction to the use of setUTCFullYear() method in JavaScript_Basic knowledge
The javascript Date.setUTCFulYear() method sets the whole year to the specified date according to universal time.
Grammar
Date.setUTCFullYear(yearValue[, monthValue[, dayValue]])
Note: The data inside and outside the brackets are optional
Here are the details of the parameters:
If the monthValue and dayValue parameters are not specified, the values returned from the getMonth and getDate methods are used. If the specified parameter is outside the expected range, calling setUTCFullYear attempts to update the corresponding date information of the other parameters and 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.
Return value:
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