Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Date.prototype

此文件需要技術審查。看看您能幫什麼忙。

Date.prototype 屬性表示 Date 建構子的原型。

Property attributes of Date.prototype
Writable no
Enumerable no
Configurable yes

描述

JavaScript Date 實體繼承自 Date.prototype。你可以藉由改變建構子的原型物件,來影響所有繼承自 JavaScript Date 的實體。

為了千年年份(換個說法,考慮現在已到了 2000 年)的相容性,設定上你應該採用完整的年份。舉例來說,使用 1998 而不是 98 。為了讓你能取得完整的年份資料, Javascript 包含了 getFullYear()setFullYear()getUTCFullYear() 以及 setUTCFullYear() 方法。

自 ECMAScript 6 開始, Date.prototype 物件只是個一般物件,而不是一個 Date 實體。

屬性

Date.prototype.constructor
回傳一個能建立實體的函數,這是 Date 預設的建構子。

方法

Getter

Date.prototype.getDate()
回傳本地時間月份中的日期(1-31)。
Date.prototype.getDay()
回傳本地時間星期中的日子(0-6)。
Date.prototype.getFullYear()
回傳本地時間的年份( 以 4 位數表現)。
Date.prototype.getHours()
回傳本地時間的小時(0-23)。
Date.prototype.getMilliseconds()
回傳本地時間的毫秒數(0-999)。
Date.prototype.getMinutes()
回傳本地時間的分鐘數(0-59)。
Date.prototype.getMonth()
回傳本地時間的月份(0-11)。
Date.prototype.getSeconds()
回傳本地時間的秒數(0-59)。
Date.prototype.getTime()
回傳由 1970-01-01 00:00:00 UTC 開始,到代表時間經過的毫秒數(以負值表示 1970 年之前的時間)。
Date.prototype.getTimezoneOffset()
回傳本地時差為多少分鐘。
Date.prototype.getUTCDate()
回傳標準時間的在月份中的日期(1-31)。
Date.prototype.getUTCDay()
回傳標準時間在星期中的日子(0-6)。
Date.prototype.getUTCFullYear()
回傳標準時間的年份( 以 4 位數表現)。
Date.prototype.getUTCHours()
回傳標準時間的小時數(0-23)。
Date.prototype.getUTCMilliseconds()
回傳標準時間裡的毫秒數(0-999)。
Date.prototype.getUTCMinutes()
回傳標準時間的分鐘數(0-59)。
Date.prototype.getUTCMonth()
回傳標準時間的月份數(0-11)。
Date.prototype.getUTCSeconds()
回傳標準時間的秒數(0-59)。
Date.prototype.getYear()
回本地時間的年份(通常 2-3 位數)。用 getFullYear() 取代。

Setter

Date.prototype.setDate()
設定本地時間月份中的日期。
Date.prototype.setFullYear()
設定本地時間的完整年份(以 4 位數表達 4 位數年份)。
Date.prototype.setHours()
設定本地時間的小時數。
Date.prototype.setMilliseconds()
設定本地時間的毫秒數。
Date.prototype.setMinutes()
設定本地時間的分鐘數。
Date.prototype.setMonth()
設定本地時間的月份。
Date.prototype.setSeconds()
設定本地時間的秒數。
Date.prototype.setTime()
設定這個 Date 物件距 1970-01-01 00:00:00 UTC 的毫秒數,允許使用負值表示之前的時間。
Date.prototype.setUTCDate()
設定標準時間月份中的日期。
Date.prototype.setUTCFullYear()
設定標準時間的完整年份(以 4 位數表示 4 位數年分)。
Date.prototype.setUTCHours()
設定標準時間的小時數。
Date.prototype.setUTCMilliseconds()
設定標準時間的毫秒數。
Date.prototype.setUTCMinutes()
設定標準時間的分鐘數。
Date.prototype.setUTCMonth()
設定標準時間的月份數。
Date.prototype.setUTCSeconds()
設定標準時間的秒數。
Date.prototype.setYear()
設定本地時間的年份(使用 2-3 位數)。使用 setFullYear() 取代。

Conversion getter

Date.prototype.toDateString()
以可閱讀的字串型式,回傳 Date 的部分資訊。
Date.prototype.toISOString()
將日期時間轉換成 ISO 8601 格式的字串回傳。
Date.prototype.toJSON()
回傳等義於 Date 物件使用 toISOString() 方法的結果。特別使用 JSON.stringify() 處理。
Date.prototype.toGMTString()
回傳 Date 以 GMT (UT) 時區基準代表的時間字串。使用 toUTCString() 方法來取代。
Date.prototype.toLocaleDateString()
依照系統的時間地區設定,回傳日期字串。
Date.prototype.toLocaleFormat()
傳入格式化字串參數,將日期時間轉換成指定格式的字串。
Date.prototype.toLocaleString()
回傳依系統的地區設定導出的日期時間字串。覆寫自 Object.prototype.toLocaleString() 方法。
Date.prototype.toLocaleTimeString()
回傳依系統的地區設定導出的時間字串。
Date.prototype.toSource()
回傳一個建立相同 Date 物件的程式碼字串;你可以拿這個結果來建立新物件。覆寫自 Object.prototype.toSource() 方法。
Date.prototype.toString()
回傳代表此 Date 物件的字串。覆寫自 Object.prototype.toString() 方法。
Date.prototype.toTimeString()
以人類可讀的格式,回傳時間部分的字串。
Date.prototype.toUTCString()
依 UTC 時區,轉換出時間日期字串。
Date.prototype.valueOf()
回傳 Date 物件的原始數值。覆寫自 Object.prototype.valueOf() 方法。

規範

規範 狀態
ECMAScript 1st Edition (ECMA-262) Standard 初步定義。實作在 JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Date.prototype' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Date.prototype' in that specification.
Standard  
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Date.prototype' in that specification.
Draft  

瀏覽器相容性

平台 Chrome Firefox (Gecko) Internet Explorer Opera Safari
基本支援 (Yes) (Yes) (Yes) (Yes) (Yes)
一般物件 ? 41 (41) ? ? ?
平台 Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
基本支援 (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
一般物件 ? ? 41.0 (41) ? ? ?

文件標籤與貢獻者

 此頁面的貢獻者: ddtet
 最近更新: ddtet,