ES6 - setFullYear() 方法



Javascript 的 `date setFullYear()` 方法根據本地時間設定指定日期的年份。

語法

Date.setFullYear(yearValue[, monthValue[, dayValue]])       

引數

  • yearValue − 指定年份的數值,例如 2008。

  • monthValue − 一個介於 0 到 11 之間的整數,代表 1 月到 12 月。

  • dayValue − 一個介於 1 到 31 之間的整數,代表月份中的某一天。如果指定了 `dayValue` 引數,則也必須指定 `monthValue`。

  • 如果不指定 `monthValue` 和 `dayValue` 引數,則使用 `getMonth` 和 `getDate` 方法返回的值。

示例

var dt = new Date( "Aug 28, 2008 23:30:00" ); 
dt.setFullYear( 2000 ); 
console.log( dt )     

輸出

Mon Aug 28 2000 23:30:00 GMT+0530 (India Standard Time)      
廣告
© . All rights reserved.