透過JS Date可取得時間參數
date=new Date()
date.xxxxx() 各Function結果如下:
.toLocaleString() -> 2022/6/26 上午9:30:16
- 本地時間字串
.toUTCString() -> Sun, 26 Jun 2022 01:30:16 GMT
- 格林威治時間,星期,dd mm yyyy hh:mm:ss
.toISOString() ->2022-06-26T01:30:16.107Z
.toJSON()-> 2022-06-26T01:30:16.107Z
- toISOString(), toJSON() 回傳值相同
.toLocaleTimeString()->上午9:30:16
- client本地時間
.toTimeString ->09:30:16 GMT+0800 (台北標準時間)
- client本地時間
- 若要取時間格式hh:mm:ss 則可用date.toTimeString().subString(0,8)取得時間部分
.toDateString()->Sun Jun 26 2022
- client本地時間
.toLocaleDateString()->2022/6/26
- client本地日期
.getFullYear()->2022
- client本地時間,此方法可完整顯示yyyy
.getYear()->122
- 此方法顯示122;由1900年後開始計算,因此2022-1900=122
.getMonth()->5
- client本地月,從0開始計算,因此要+1
.getDate()->26
- client本地日
.getDay()->0
- client星期
.getTimezoneOffset()-> -480
- client與格林威治時區的時差(分)
----
date=new Date()
console.log('getTime():'+date.getTime())
console.log('getUTCHours():'+date.getUTCHours())
console.log('getUTCMinutes():'+date.getUTCMinutes())
console.log('getUTCSeconds():'+date.getUTCSeconds())
console.log('getUTCDate():'+date.getUTCDate())
console.log('getUTCDay():'+date.getUTCDay())
console.log('getFullYear:'+date.getFullYear())
console.log('getYear:'+date.getYear())
console.log('getMonth:'+date.getMonth())
console.log('getDate:'+date.getDate())
console.log('getTimezoneOffset:'+date.getTimezoneOffset())
console.log('toDateString:'+date.toDateString())
console.log('toISOString:'+date.toISOString())
console.log('toLocaleDateString:'+date.toLocaleDateString())
console.log('toLocaleString:'+date.toLocaleString())
console.log('toUTCString:'+date.toUTCString())
console.log('toJSON:'+date.toJSON())
console.log('toLocaleTimeString:'+date.toLocaleTimeString())
console.log('toTimeString:'+date.toTimeString())