JavaScript Date setYear() Method

Description

Javascript date setYear() method sets the year for a specified date according to universal time.

Syntax

Its syntax is as follows −

Date.setYear(yearValue)

Note − Parameters in the bracket are always optional.

Parameter Detail

yearValue − An integer value.

Example

Try the following example.

<html>
   
   <head>
      <title>JavaScript setYear Method</title>
   </head>
   
   <body>
      
      <script type="text/javascript">
         var dt = new Date( "Aug 28, 2008 13:30:00" );
         dt.setYear( 2000 );
         document.write( dt ); 
      </script>
   
   </body>
</html>

Output

Mon Aug 28 2000 13:30:00 GMT+0530 (India Standard Time)