Skip to content

Latest commit

 

History

History
87 lines (68 loc) · 2.73 KB

File metadata and controls

87 lines (68 loc) · 2.73 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
setFullYear Method (Date) (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
setFullYear
JavaScript
TypeScript
DHTML
Year method
setFullYear method
dates, setting
635e4f5a-0210-4c01-8152-b0da4146f6ff
16
mikejo5000
mikejo
ghogen

setFullYear Method (Date) (JavaScript)

Sets the year of the Date object using local time.

Syntax

  
dateObj.setFullYear(numYear[, numMonth[, numDate]])   

Parameters

dateObj
Required. Any Date object.

numYear
Required. A numeric value for the year.

numMonth
Optional. A zero-based numeric value for the month (0 for January, 11 for December). Must be specified if numDate is specified.

numDate
Optional. A numeric value equal for the day of the month.

Remarks

All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify the optional argument. For example, if the numMonth argument is optional, but not specified, [!INCLUDEjavascript] uses the value returned from the getMonth method.

In addition, if the value of an argument is greater than its calendar range or is negative, the date rolls forward or backward as appropriate.

To set the year using Universal Coordinated Time (UTC), use the setUTCFullYear method.

The range of years supported in the date object is approximately 285,616 years before and after 1970.

Example

The following example illustrates the use of the setFullYear method:

var date1 = new Date("1/1/2001");  
date1.setFullYear(2007);  
  
var date2 = new Date("1/1/2001");  
date2.setFullYear(2008, 10, 3);   
  
document.write (date1.toLocaleString());  
document.write ("<br />");  
document.write (date2.toLocaleString());  
  
// Output:  
// Monday, January 01, 2007 12:00:00 AM  
// Monday, November 03, 2008 12:00:00 AM  

Requirements

[!INCLUDEjsv3]

Applies To: Date Object

See Also

getFullYear Method (Date)
getUTCFullYear Method (Date)
setUTCFullYear Method (Date)