uniapp掘墓者之IOS時間格式
阿新 • • 發佈:2021-01-23
最近發現了一個小坑,特此記錄一下
let str = '2020-01-20 15:34:24';
new Date(str)
// Andriod
// Mon Jan 20 2020 15:34:24 GMT+0800 (中國標準時間)
// Ios
// Invalid Date
原因在於Ios
只能識別/
這種格式的時間格式,所以改成如下程式碼
let str = '2020-01-20 15:34:24'; let os = uni.getSystemInfoSync().platform; if(os == 'ios'){ str = str.replace(/-/g,'/'); } new Date(str) //Andriod //ios //Mon Jan 20 2020 15:34:24 GMT+0800 (中國標準時間)
個人部落格:點此進入(http://xueshuai.top)
前端交流群:1063233592