当我从日期转换为字符串时,我的日期正在改变。我的错是什么?
Date返回给我:
Date 2016-10-31T22:00:00.000Z
当我转换成字符串时,我得到:
Thu Dec 01 2016 00:00:00 GMT+0200
我的代码:
date = new Date("2016 11 31");
StringDate = date.toString();
console.log(StringDate);
console.log(date);
发布于 2016-08-13 16:17:22
您正在等待UTC时间,可以使用Date.toUTCString()
打印该时间
var date = new Date("2016 11 31");
var stringDate = date.toUTCString(); // See this line
console.log(stringDate);
console.log(date);
发布于 2016-08-13 16:24:01
实际上,您的输入是wrong.There,而不是这样的2016-11-31
。这就是为什么它会显示2016年12月1日。
试试这个:
date=new Date("2016 10 31"); //november consist 30 days only
StringDate=date.toString();
console.log(StringDate);
console.log(date);
https://stackoverflow.com/questions/38934594
复制