0
    function getGmtToLocal(gmtDateTime) {
    var curdatetime = new Date();
    var curDate = curdatetime.getDate();
    var curMon = curdatetime.getMonth();
    var curYear = curdatetime.getFullYear();
    var localCurdate = curdatetime.toLocaleString();
    var curdt = curDate + "/" + curMon + "/" + curYear;
    var tomcurrdt = (parseInt(curDate) + 1) + "/" + curMon + "/" + curYear;

    var myDate = new Date(gmtDateTime);
    var gmtDate = myDate.getDate();
    var gmtMon = myDate.getMonth();
    var gmtYear = myDate.getFullYear();
    var localGmt = myDate.toLocaleString();
    var gmtdt = gmtDate + "/" + gmtMon + "/" + gmtYear;
    var day;
    var tomgmtdt = (parseInt(gmtDate) + 1) + "/" + gmtMon + "/" + gmtYear;

    if (gmtdt == curdt) {
        day = 'Today';
    } else if (tomgmtdt == tomcurrdt) {
        day = 'Tommorrow';
    } else {
        var dt = myDate.getDate();
        var dayno = myDate.getDay();
        var day_name = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        var monthno = myDate.getMonth();
        var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"];

        var hours = myDate.getHours() > 12 ? myDate.getHours() - 12 : myDate.getHours();
        var am_pm = myDate.getHours() >= 12 ? "PM" : "AM";
        hours = hours < 10 ? "0" + hours : hours;
        var minutes = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();
        var seconds = myDate.getSeconds() < 10 ? "0" + myDate.getSeconds() : myDate.getSeconds();
        var time = hours + ":" + minutes + " " + am_pm;

        day = day_name[dayno] + ', ' + months[monthno] + ' ' + dt + ', ' + time;
    }
    return day;

}

I am using this function and I am getting "undefined, undefined NaN, NaN: NaN AM" can you help me find out the solution to it .......................................

  • Works just fine for me. – Akrion Dec 07 '18 at 05:47
  • 1
    What is the value of *gmtDateTime*? Probably a duplicate of [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Dec 07 '18 at 06:07
  • Note that *curMon* will likely be one less than you expect since months are zero indexed and you don't seem to be allowing for that. – RobG Dec 07 '18 at 06:08

0 Answers0