JS——Date日期對象

1.Date對象的四種建立方法分別是什麼?ios

new Date()

new Date(milliseconds)

new Date(dateString)

new Date(year,month,day,hours,minutes,seconds,milliseconds)

1.1 dateString時間字符串的三種格式格式
通用格式:年/月/日 空格 時:分:秒(示例:2020/07/15 16:53:56)
短橫杆式:xxxx-xx-xx xx:xx:xx(chrome firefox opera)
斜杆式:xxxx/xx/xx xx:xx:xx(chrome firefox opera safari ios(蘋果手機只認此格式))
點式:xxxx.xx.xx xx:xx:xx(chrome opera)chrome

2.兩個Date對象屬性及其做用是什麼?函數

constructor:返回對建立此對象的 Date 函數的引用。Date對象的函數原型。firefox

myDate.constructor;

prototype:建立一個新的日期對象方法prototype

Date.prototype.methods

3.經常使用的Date對象方法有哪些?code

getFullYear()	      從 Date 對象以四位數字返回年份。
getMonth()	      從 Date 對象返回月份 (0 ~ 11)。
getDate()	      從 Date 對象返回一個月中的某一天 (1 ~ 31)。
getHours()	      返回 Date 對象的小時 (0 ~ 23)。
getMinutes()	      返回 Date 對象的分鐘 (0 ~ 59)。
getSeconds()	      返回 Date 對象的秒數 (0 ~ 59)。
getMilliseconds()     返回 Date 對象的毫秒(0 ~ 999)。
getTime()	      返回 1970 年 1 月 1 日至今的毫秒數。
getDay()	      從 Date 對象返回一週中的某一天 (0 ~ 6)。
相關文章
相關標籤/搜索