Firefox NaN错误但可以正常使用chrome

时间:2016-05-06 09:23:12

标签: javascript jquery firefox timestamp

我有一个代码将数据放入数据表中并进行时间计算:

$.each(myObj[1], function(key,value) {
    var date_start = new Date(value.start_timestamp);
    var date_end = new Date(value.end_timestamp);
    var milisec = Math.abs(date_end - date_start);
    var seconds = milisec / 1000;
    var hours = parseFloat( seconds / 3600 );
    totalhours += hours;

    var isdaily = '';
    if(value.is_daily == 0)
    {
        isdaily = 'Added'
    }
    else
    {
        isdaily = 'Daily'
    }

    t.row.add( [
        value.id,
        value.task_description,
        value.start_timestamp,
        value.end_timestamp,
        hours.toFixed(2)+" hr(s)",
        value.name,
        value.assign,
        value.created_at,
        isdaily,
        value.status
    ] ).draw();
});

var final_compute = Math.ceil(totalhours.toFixed(2));
$('#totalhours').text(final_compute);
alert("Tasks from the last 12 hours generated.");

我的变量milisec, seconds, hoursNaN值,会发生什么。结果是date_startdate_end导致无效日期造成的。但是在Chrome上运行正常。我的时间戳格式类似于2016-05-04 23:00:00

1 个答案:

答案 0 :(得分:0)

您需要提供特定格式才能解析Firefox中的日期。更多信息can be found here