今天發現一個bug,時間處理異常,安卓是沒問題,逐步排查發現問題出在時間字符串轉時間戳的地方,new Date("2020-06-18 19:00:00").getTime()返回NAN,但是在windows的chrome瀏覽器控制檯中調試一點問題都沒有,於是
console.log(1, new Date("2020-01-01 01:01:01").getTime())
console.log(1, new Date("2020-06-01 01:01:01").getTime())
console.log(1, new Date("2020/01/01 01:01:01").getTime())
console.log(1, new Date("2020/06/01 01:01:01").getTime())
在多種設備上嘗試,發現ios上對yyyy-MM-dd hh:mm:ss格式的日期解析有問題,只能解析yyyy/MM/dd hh:mm:ss格式的時間,但是時間字符串是後臺返回的,於是只能
var ios_time = this.reportData.time.replace(/-/g, '/')
var ios_end_time = this.reportData.end_time.replace(/-/g, '/')
this.startTime = parseInt(new Date(ios_time).getTime()/1000)
this.endTime = parseInt(new Date(ios_end_time).getTime()/1000)
將格式轉換,'-' ===> '/'