兼容火狐浏览器
作者:互联网
1. 日期
let time =‘2017-12-13T09:47:07.153+08:00’
if (typeof time === 'string') {
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
}
let date = new Date(time)
如上,在谷歌浏览器中没问题,但在火狐浏览器中,Invalid date;原因是time正则后为‘2017-12-13 09:47:07+08:00’,但火狐接收的格式是‘2017-12-13 09:47:07’;
所以正则需要再修改一下
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}\+[\d]{2}:[\d]{2}/gm), '');
标签:浏览器,47,RegExp,replace,火狐,time,new,gm,兼容 来源: https://www.cnblogs.com/lololo/p/16230508.html