木田网

为避免出现兼容性、时区错误,建议在接口、传参过程中统一使用以下时间格式:

避免/禁止使用以下格式:

不同时间格式 new Date() 后的结果:


时间格式 Chrome (Android) Safari (iOS) IE
参数为UTC时间

new Date('2021-01-01T00:00:00+00:00')
new Date('2021-01-01T00:00:00Z')

Fri Jan 01 2021 08:00:00 GMT+0800 (China Standard Time)
Fri Jan 01 2021 08:00:00 GMT+0800 (CST)
new Date('2021-01-01 00:00:00+00:00') Fri Jan 01 2021 08:00:00 GMT+0800 (China Standard Time) Invalid Date
new Date('2021-01-01 00:00:00Z') Fri Jan 01 2021 08:00:00 GMT+0800 (China Standard Time) Invalid Date
new Date('2021-01-01T00:00:00') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Fri Jan 01 2021 00:00:00 GMT+0800 (CST)
new Date('2021/01/01T08:00:00') Invalid Date Invalid Date
参数为本地时间 new Date('2021/01/01 00:00:00') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Fri Jan 01 2021 00:00:00 GMT+0800 (CST)
new Date('2021/01/01') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Fri Jan 01 2021 00:00:00 GMT+0800 (CST)
new Date('2021/1/1') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Fri Jan 01 2021 00:00:00 GMT+0800 (CST)
new Date('2021-01-01 00:00:00') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Invalid Date
new Date('2021-01-01') Fri Jan 01 2021 08:00:00 GMT+0800 (China Standard Time) Fri Jan 01 2021 08:00:00 GMT+0800 (CST) 印象中不兼容
new Date('2021-1-1') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Invalid Date
new Date('2021,1,1') Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Invalid Date
new Date(2021,0,1) Fri Jan 01 2021 00:00:00 GMT+0800 (China Standard Time) Fri Jan 01 2021 00:00:00 GMT+0800 (CST)

参考