Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Internet Explorer中,无法将UTC日期转换为本地日期_Javascript_Date_Internet Explorer 11_Momentjs_Datejs - Fatal编程技术网

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(印度标准时间)”
但在Internet Explorer上:

  • 调用:
    新日期('2017-05-23T18:30:00')。toString()
  • 结果:
    “2017年5月23日星期二18:30:00 GMT+0530(印度标准时间)”
当我进入Chrome浏览器时,如何从Internet Explorer中的UTC日期获取本地日期时间?

您可以使用它跨浏览器解析输入。然后可以使用显示力矩对象。若您需要将矩对象转换为JavaScript日期,可以使用方法

如果要将时刻转换为本地时间,请使用

有关更多信息,请参阅

这里有一个活样本:

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谢谢您的工作