欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS中 new Date() 各方法的用法說(shuō)明

 更新時(shí)間:2022年12月19日 16:10:35   作者:Xie_bro777  
這篇文章主要介紹了JS中 new Date() 各方法的用法,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

JS中 new Date() 各方法的用法

1.new Date() 參數(shù)篇

a.返回類型為國(guó)標(biāo)時(shí)間,
b.無(wú)參數(shù)時(shí)可以直接返回輸出時(shí)的時(shí)間,
c.有參數(shù)時(shí)則返回對(duì)應(yīng)時(shí)間的國(guó)標(biāo)時(shí)間,
d.日期中間的符號(hào)可以為,(英文逗號(hào)) - / . * = !@ # ¥ % & ,不可為~ · ` ^ + ,(中文逗號(hào)) 。

new Date()
Sun Aug 21 2022 15:22:09 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("2022-01-01")
Sat Jan 01 2022 08:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("2022/01/01")
Sat Jan 01 2022 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("2022.01.01")
Sat Jan 01 2022 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("2022*01*01")
Sat Jan 01 2022 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("Sat Jan 2022")
Sat Jan 01 2022 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間) 

注1:英文括號(hào) 都為左括號(hào) 或一對(duì)括號(hào) ,兩個(gè)右括號(hào)無(wú)法識(shí)別

new Date("2022(01)01")
Sat Jan 01 2022 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("2022(01(01")
Sat Jan 01 2022 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

new Date("2022)01)01")
Invalid Date 	// 無(wú)效的時(shí)間

注2:也可以用六個(gè)參數(shù)表示日期時(shí)間的各個(gè)數(shù)值
其中第二個(gè)參數(shù)代表月份減一,即參數(shù)為1時(shí),其實(shí)是二月,第三個(gè)參數(shù)為0,代表上個(gè)月的最后一天

new Date("2022","01",0,11,12,20)
Mon Jan 31 2022 11:12:20 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

注3:入?yún)闀r(shí)間戳?xí)r 返回對(duì)應(yīng)的國(guó)標(biāo)時(shí)間

new Date(1661051533000)		
//Sun Aug 21 2022 11:12:13 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)

2.方法篇

查詢一個(gè)月有多少天

//2022年一月份的天數(shù)
new Date("2022","01",0).getDate() 				// 31

日常方法

入?yún)⑷掌诘?時(shí)間戳
new Date("2022-08-21 11:12:13").getTime() 		// 1661051533000

入?yún)⑷掌诘?星期(注:日:0 ,一:1,二:2,三:3,四:4,五:5,六:6)
new Date("2022-08-21 11:12:13").getDay()        // 0

入?yún)⑷掌诘?年
new Date("2022-08-21 11:12:13").getFullYear()  	// 2022

入?yún)⑷掌诘?月 -1 
new Date("2022-08-21 11:12:13").getMonth()  	// 7

入?yún)⑷掌诘?日
new Date("2022-08-21 11:12:13").getDate() 		// 21

入?yún)⑷掌诘?時(shí)
new Date("2022-08-21 11:12:13").getHours() 		// 11

入?yún)⑷掌诘?分
new Date("2022-08-21 11:12:13").getMinutes()  	// 12

入?yún)⑷掌诘?秒
new Date("2022-08-21 11:12:13").getSeconds() 	// 13

入?yún)⑷掌诘?毫秒 (注:最大為999)
new Date("2022-08-21 11:12:13:999").getMilliseconds()  //999

入?yún)⑷掌?距 1900年的年數(shù)

new Date("2022-08-21 11:12:13").getYear() 		// 122

3.國(guó)標(biāo)時(shí)間、時(shí)間戳、年月日 時(shí)分秒的轉(zhuǎn)換

//vue  js 文件
handlerZero(param){
	param= param<10?('0'+param):param
},
// 國(guó)標(biāo)時(shí)間 轉(zhuǎn) 年月日 時(shí)分秒
formatDateTime(date) {
    let y = date.getFullYear()
    let m = date.getMonth()+1
    let d = date.getDate()
    let h = date.getHours()
    let h = date.getHours()
    let mi = date.getMinutes()
    let ss = date.getSeconds()
    return y+this.handlerZero(m)+this.handlerZero(d)+this.handlerZero(h)+this.handlerZero(mi)+this.handlerZero(ss)
},
// 時(shí)間戳轉(zhuǎn)年月日 時(shí)分秒
formatDateTime2(date) {
    let datee = new Date(date)
    return this.formatDateTime(datee)
},
// 年月日 轉(zhuǎn) 時(shí)間戳
formatDateTime3(date) {
    let y = date.substring(0,4)
    let m = date.substring(4,6)
    let d = date.substring(6,8)
    let str = y+'-'+m+'-'+d 
    return new Date(str).getTime()
}

到此這篇關(guān)于JS中 new Date() 各方法的用法的文章就介紹到這了,更多相關(guān)JS中 new Date() 各方法的用法內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論