Javascript 在Internet Explorer中,无法将UTC日期转换为本地日期
这是我从后端收到的日期Javascript 在Internet Explorer中,无法将UTC日期转换为本地日期,javascript,date,internet-explorer-11,momentjs,datejs,Javascript,Date,Internet Explorer 11,Momentjs,Datejs,这是我从后端收到的日期“2017-05-23T18:30:00” 这在铬合金中工作良好: 调用:新日期('2017-05-23T18:30:00')。toString() 结果:“2017年5月24日星期三00:00:00 GMT+0530(印度标准时间)” 但在Internet Explorer上: 调用:新日期('2017-05-23T18:30:00')。toString() 结果:“2017年5月23日星期二18:30:00 GMT+0530(印度标准时间)” 当我进入Chrom
“2017-05-23T18:30:00”
这在铬合金中工作良好:
- 调用:
新日期('2017-05-23T18:30:00')。toString()
- 结果:
“2017年5月24日星期三00:00:00 GMT+0530(印度标准时间)”
- 调用:
新日期('2017-05-23T18:30:00')。toString()
- 结果:
“2017年5月23日星期二18:30:00 GMT+0530(印度标准时间)”
var输入='2017-05-23T18:30:00';
var m=时刻utc(输入);
console.log(m.format());
log(m.toDate().toString())代码>
IE浏览器将采用“mm-dd-yy”格式。如果您以“yy-mm-dd”格式提供,则结果为无效日期
使用以下函数将UTC转换为LocalDate
function convertUTCDateToLocalDate(utcDate) {
var formattedDate = utcDate.getMonth()+'-'+utcDate.getDate()+'-'+utcDate.getFullYear();
var hours = utcDate.getHours();
var minutes = utcDate.getMinutes();
var seconds = utcDate.getSeconds()
var newDate = new Date(formattedDate + ' ' + hours + ':' + minutes+":"+seconds+" UTC");
return newDate;
}
var localDate = convertUTCDateToLocalDate(yourUTCDate);
如果您特别将时间标记为UTC:2017-05-23T18:30:00Z
@Henry谢谢您的工作