IOS16 以下版本new Date('2022-12-12 00:00:00') 报invalid Date
原因为:IOS16 以下版本浏览器内核,不支持 “-” 连接日期,支持用“/”连接日期,不能直接使用 new Date("2022-12-12 00:00:00"), 正确格式应为 new Date("2022/12/12 00:00:00")
修改方式可使用如下两种:
1. 替换 “-” 为 “/”
new Date("2022-12-12 00:00:00".replace(/-/g, '/'));
2. 使用moment.js
// 安装 moment.js
npm install moment --save
//导入moment
import moment from 'moment';
//使用moment设置时间
moment('2022-12-12 00:00:00');
官方文档:moment.js 中文网
3. 使用dayjs
// 安装dayjs
npm install dayjs --save
// 导入dayjs
import dayjs from 'dayjs';
// 使用dayjs 设置时间
dayjs('2022-12-12 00:00:00');
使用参考:Day.js 常用方法
官方文档:Day.js 中文网
Comments | NOTHING