JavaScript Date 對(duì)象
Date 對(duì)象
Date 對(duì)象用于處理日期和時(shí)間。
創(chuàng)建 Date 對(duì)象的語(yǔ)法:
var myDate=new Date()
注釋?zhuān)?/span>Date 對(duì)象會(huì)自動(dòng)把當(dāng)前日期和時(shí)間保存為其初始值。
Date 對(duì)象屬性
屬性 | 描述 |
---|---|
constructor | 返回對(duì)創(chuàng)建此對(duì)象的 Date 函數(shù)的引用。 |
prototype | 使您有能力向?qū)ο筇砑訉傩院头椒ā?/td> |
Date 對(duì)象方法
方法 | 描述 |
---|---|
Date() | 返回當(dāng)日的日期和時(shí)間。 |
getDate() | 從 Date 對(duì)象返回一個(gè)月中的某一天 (1 ~ 31)。 |
getDay() | 從 Date 對(duì)象返回一周中的某一天 (0 ~ 6)。 |
getMonth() | 從 Date 對(duì)象返回月份 (0 ~ 11)。 |
getFullYear() | 從 Date 對(duì)象以四位數(shù)字返回年份。 |
getYear() | 請(qǐng)使用 getFullYear() 方法代替。 |
getHours() | 返回 Date 對(duì)象的小時(shí) (0 ~ 23)。 |
getMinutes() | 返回 Date 對(duì)象的分鐘 (0 ~ 59)。 |
getSeconds() | 返回 Date 對(duì)象的秒數(shù) (0 ~ 59)。 |
getMilliseconds() | 返回 Date 對(duì)象的毫秒(0 ~ 999)。 |
getTime() | 返回 1970 年 1 月 1 日至今的毫秒數(shù)。 |
getTimezoneOffset() | 返回本地時(shí)間與格林威治標(biāo)準(zhǔn)時(shí)間 (GMT) 的分鐘差。 |
getUTCDate() | 根據(jù)世界時(shí)從 Date 對(duì)象返回月中的一天 (1 ~ 31)。 |
getUTCDay() | 根據(jù)世界時(shí)從 Date 對(duì)象返回周中的一天 (0 ~ 6)。 |
getUTCMonth() | 根據(jù)世界時(shí)從 Date 對(duì)象返回月份 (0 ~ 11)。 |
getUTCFullYear() | 根據(jù)世界時(shí)從 Date 對(duì)象返回四位數(shù)的年份。 |
getUTCHours() | 根據(jù)世界時(shí)返回 Date 對(duì)象的小時(shí) (0 ~ 23)。 |
getUTCMinutes() | 根據(jù)世界時(shí)返回 Date 對(duì)象的分鐘 (0 ~ 59)。 |
getUTCSeconds() | 根據(jù)世界時(shí)返回 Date 對(duì)象的秒鐘 (0 ~ 59)。 |
getUTCMilliseconds() | 根據(jù)世界時(shí)返回 Date 對(duì)象的毫秒(0 ~ 999)。 |
parse() | 返回1970年1月1日午夜到指定日期(字符串)的毫秒數(shù)。 |
setDate() | 設(shè)置 Date 對(duì)象中月的某一天 (1 ~ 31)。 |
setMonth() | 設(shè)置 Date 對(duì)象中月份 (0 ~ 11)。 |
setFullYear() | 設(shè)置 Date 對(duì)象中的年份(四位數(shù)字)。 |
setYear() | 請(qǐng)使用 setFullYear() 方法代替。 |
setHours() | 設(shè)置 Date 對(duì)象中的小時(shí) (0 ~ 23)。 |
setMinutes() | 設(shè)置 Date 對(duì)象中的分鐘 (0 ~ 59)。 |
setSeconds() | 設(shè)置 Date 對(duì)象中的秒鐘 (0 ~ 59)。 |
setMilliseconds() | 設(shè)置 Date 對(duì)象中的毫秒 (0 ~ 999)。 |
setTime() | 以毫秒設(shè)置 Date 對(duì)象。 |
setUTCDate() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中月份的一天 (1 ~ 31)。 |
setUTCMonth() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中的月份 (0 ~ 11)。 |
setUTCFullYear() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中的年份(四位數(shù)字)。 |
setUTCHours() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中的小時(shí) (0 ~ 23)。 |
setUTCMinutes() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中的分鐘 (0 ~ 59)。 |
setUTCSeconds() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中的秒鐘 (0 ~ 59)。 |
setUTCMilliseconds() | 根據(jù)世界時(shí)設(shè)置 Date 對(duì)象中的毫秒 (0 ~ 999)。 |
toSource() | 返回該對(duì)象的源代碼。 |
toString() | 把 Date 對(duì)象轉(zhuǎn)換為字符串。 |
toTimeString() | 把 Date 對(duì)象的時(shí)間部分轉(zhuǎn)換為字符串。 |
toDateString() | 把 Date 對(duì)象的日期部分轉(zhuǎn)換為字符串。 |
toGMTString() | 請(qǐng)使用 toUTCString() 方法代替。 |
toUTCString() | 根據(jù)世界時(shí),把 Date 對(duì)象轉(zhuǎn)換為字符串。 |
toLocaleString() | 根據(jù)本地時(shí)間格式,把 Date 對(duì)象轉(zhuǎn)換為字符串。 |
toLocaleTimeString() | 根據(jù)本地時(shí)間格式,把 Date 對(duì)象的時(shí)間部分轉(zhuǎn)換為字符串。 |
toLocaleDateString() | 根據(jù)本地時(shí)間格式,把 Date 對(duì)象的日期部分轉(zhuǎn)換為字符串。 |
UTC() | 根據(jù)世界時(shí)返回 1970 年 1 月 1 日 到指定日期的毫秒數(shù)。 |
valueOf() | 返回 Date 對(duì)象的原始值。 |