今天使用 js 发现了问题
console.log(new Date('2019,12,16,18,00,00'))
输出结果为
Invalid Date
大致查了一下 是因为浏览器没有兼容,需要改一下日期的格式
new Date("month dd,yyyy hh:mm:ss");
new Date("month dd,yyyy");
new Date(yyyy,mth,dd,hh,mm,ss);
new Date(yyyy,mth,dd);
new Date(ms);
month:用英文表示月份名称;
mth:用整数表示月份;
dd:表示一个月中的第几天;
yyyy:四位数表示的年份;
hh:小时数;
mm:分钟数;
ss:秒数;
ms:毫秒数;
解决代码:
var time = "2017-06-23 17:00:00";
time = time.replace(/-/g,':').replace(' ',':');
time = time.split(':');
var time1 = new Date(time[0],(time[1]-1),time[2],time[3],time[4],time[5]);
console.log("time1"+time1);