Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In this fiddle, the values for

     new Date(val[0]).getTime()

differ in Chrome and IE. The chrome values appear to be proper, Is there a workaround to get the values correct in IE.

Code:

$(function () {
        var text="";
    $.each($.parseJSON("[{"name":"critical","data":[["2013-10-01T00:00:00",830],["2013-10-02T00:00:00",257],["2013-10-03T00:00:00",160],["2013-10-04T00:00:00",200]]},{"name":"normal","data":[["2013-10-01T00:00:00",24],["2013-10-02T00:00:00",20],["2013-10-03T00:00:00",13],["2013-10-04T00:00:00",30]]},{"name":"ignore","data":[["2013-10-01T00:00:00",1732],["2013-10-02T00:00:00",1220],["2013-10-03T00:00:00",1120],["2013-10-04T00:00:00",1500]]}]"), function (key, value) {
            $.each(value.data, function (key, val) {
                text += "["+(new Date(val[0]).getTime()).toString()+","+ val[1].toString()+"]";
            });
        }
    );
    $("#container").html(text);
    });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

Each browser is assuming a different timezone for partial ISO formats -- Chrome assumes they're in UTC while IE assumes they're local to the user.

console.log(new Date("2013-10-01T00:00:00").getUTCHours());
// Chrome: 0
// IE 10:  5 (for US/Central)

If a timezone were included in the format, such as a Z for UTC, then they should parse the same:

console.log(new Date("2013-10-01T00:00:00Z").getUTCHours());
// Chrome: 0
// IE 10:  0

console.log(new Date("2013-10-01T00:00:00-04:00").getUTCHours());
// Chrome: 4
// IE 10:  4

And, if needed, you can add it just before parsing:

new Date(val[0] + 'Z')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...