苹果X浏览模式打印Date.parse('2021-03-11 16:16:01')报NaN,真机调
发布于 6 年前 作者 xsun 6233 次浏览 来自 问答

浏览模式下调试打印Date.parse(‘2021-03-11 16:16:01’)报的是NaN,但是真机调试又没问题,很疑惑

代码片段:https://developers.weixin.qq.com/s/58VwaImh7loq

3 回复

原因:

iOS不支持对“2019-11-22”格式时间转型

将时间变成“2019/11/22”这种格式

利用正则表达式 .replace(/-/g, ‘/’) 将 “ - ” 变成 “ / ”



iOS只支持 yyyy/mm/dd这种日期格式,你需要用replace做下处理

const date = ‘2021-03-11 16:16:01

Date.parse(date.replace(/-/g, ‘/’))

iOS只支持2020/01/01 这种日期格式,不支持2020-01-01这样的格式

可以看一下这篇文章https://developers.weixin.qq.com/community/develop/article/doc/000e2e82d14cd80838c9cb8b552013

回到顶部