浏览模式下调试打印Date.parse('2021-03-11 16:16:01')报的是NaN,但是真机调试又没问题,很疑惑
代码片段:https://developers.weixin.qq.com/s/58VwaImh7loq
苹果X浏览模式打印Date.parse('2021-03-11 16:16:01')报NaN,真机调Print Date.parse('2021-03-11 16:16:01') in Apple X browser mode and report NaN, the real machine is adjusted
苹果X浏览模式打印Date.parse('2021-03-11 16:16:01')报NaN,真机调浏览模式下调试打印Date.parse('2021-03-11 16:16:01')报的是NaN,但是真机调试又没问题,很疑惑
代码片段:https://developers.weixin.qq.com/s/58VwaImh7loq
Debug print in browse mode Date.parse ('2021-03-11 16:16:01 ') reported Nan, but there was no problem in real machine debugging. I was very confused about the code fragment: https://developers.weixin.qq.com/s/58VwaImh7loq
回答:
iOS只支持2020/01/01 这种日期格式,不支持2020-01-01这样的格式
可以看一下这篇文章https://developers.weixin.qq.com/community/develop/article/doc/000e2e82d14cd80838c9cb8b552013
iOS只支持 yyyy/mm/dd这种日期格式,你需要用replace做下处理
const date = '2021-03-11 16:16:01'
Date.parse(date.replace(/-/g, '/'))
原因:
iOS不支持对“2019-11-22”格式时间转型
将时间变成“2019/11/22”这种格式
利用正则表达式 .replace(/-/g, ‘/’) 将 “ - ” 变成 “ / ”