日期功能在chrome中起作用,但在Firefox中不起作用,不确定

时间:2018-12-07 05:44:44

标签: javascript datetime

    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;

}

我正在使用此功能,并且收到“未定义,未定义的NaN,NaN:NaN AM”信息,您能帮我找出解决方案的问题吗?................ ......................

0 个答案:

没有答案