0

I try to convert UTC Time string to Local Time. In my function the sate retun Nan in IE but works on FF & Chorome.

var myDate = '2016-12-17 4:20';
var LocDate = convertUTCDateToLocalDate(new Date(myDate));
console.log(LocDate);

Output(IE): NaN-aN-aN aN:aN

function convertUTCDateToLocalDate(date) {
  if(typeof date !== undefined){
    var locDate,iYear,iMonth,iDay,iMin;
    var newDate = new Date(date);
    newDate.setMinutes(date.getMinutes() - date.getTimezoneOffset());
    iYear = newDate.getFullYear();
    iMonth = newDate.getMonth() + 1;
    iDay = newDate.getDate();
    iHrs = newDate.getHours();
    iMin = newDate.getMinutes();
    locDate = iYear + '-' + ('0' + iMonth).slice( - 2) + '-' + ('0' + iDay).slice( - 2) + ' ' + ('0' + iHrs).slice( - 2) + ':' + ('0' + iMin).slice( - 2);
    return locDate;
  }
}

How to fix for IE?

Daniel Smith
  • 1,626
  • 3
  • 29
  • 59

0 Answers0