JavaScript 中 Date 對象 getFullYear()方法的詳細解釋

來源:互聯網
上載者:User

標籤:

getFullYear()函數用於使用當地時間返回當前Date對象中的年份值。也就是"年月日"中"年"的數值。例如:2013年7月15日,就返回2013;公元前123年5月12日,就返回-123。

該函數屬於Date對象,所有主流瀏覽器均支援該函數。

文法
date.getFullYear( )
getFullYear()函數的傳回值為Number類型,返回當前Date對象的年份值

樣本&說明
// 定義一個"2013-07-21"的Date對象
var date = new Date(2013, 6, 21);
document.writeln( date.getFullYear() ); // 2013

// 定義一個"2001-06-30 12:11:59 230"的Date對象
var date2 = new Date(2001, 5, 30, 12, 11, 59, 230);
document.writeln( date2.getFullYear() ); // 2001

// 定義一個"-102-03-23"的Date對象(公元前)
var date3 = new Date(-102, 2, 23);
document.writeln( date3.getFullYear() ); // -102
 

JavaScript 中 Date 對象 getFullYear()方法的詳細解釋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.