Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript setFullYear Method



The setFullYear method sets the year value of the point in time stored in a Date object.

Besides, it can also be used to change its month, its day of the month, or to modify the date by increasing or decreasing it in a provided quantity of months or days.

The value returned by this method is the quantity of milliseconds passed since January 1st 1970 until the point in time stored in the Date object once it has been modified.


Syntax

The setFullYear method has three overloads:

myDate.setFullYear( year )

myDate.setFullYear( year, months )

myDate.setFullYear( year, months, days )

With:
  • year being a required parameter that sets the year of the point in time stored in a Date object.
  • months being an optional parameter that consists of an integer number that, when it is between 0 and 11, changes only the month value of the point in time stored in a Date object. Any month value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining months. If the parameter is an integer between 0 and 11 but the day of the month in the Date object does not exist for the month being indicated by the parameter, once the new month is assigned the point in time will be increased in a quantity equal to the days remaining in the parameter.
  • days being an optional parameter that consists of an integer number that, when it is between 1 and the last day of the month, changes only the day of the month of the point in time stored in a Date object. Any value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining days.
  • myDate being an object based on the Date object.


Example

The following code uses the setFullYear method to change the year value of the point in time stored in Date object:


Try it yourself »


Technical Details

The setFullYear method belongs to the Date object, it is available since the version 1.3 of JavaScript, and it is supported in all major browsers.





JavaScript Manual >> Date Object >> setFullYear Method



This post first appeared on ROM Cartridge, please read the originial post: here

Share the post

JavaScript setFullYear Method

×

Subscribe to Rom Cartridge

Get updates delivered right to your inbox!

Thank you for your subscription

×