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

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

javascript - Date function not working in IE8

I've got the following which works fine in Chrome:

function funLoad(str1,str3,str4)
{

    var dym1 = str1.split("/");

    var d=new Date();
    var dym2 = d.getMonth() + 1 + " " + d.getDate() + " " + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":00";
    //var dym2 = "6 10 2013 09:00:00";

    var start = Date.parse(dym1[1] + " " + dym1[0] + " " + dym1[2] + " " + str3 + ":" + str4 + ":00"); 
    var end = Date.parse(dym2);

    return (start-end) / (1000*60*60);

}

$("#btn1").click(function(event){
    alert(funLoad($("#txt1").val(),$("#ddlHourTime").val(),$("#ddlMinuteTime").val()));
});

Here is a jsFiddle: http://jsfiddle.net/oshirowanen/QTVWd/6/

When I run this in IE8, I just get alerted with NaN.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Looks like that format is not supported in IE

var dym2 = d.getMonth() + 1 + "-" + d.getDate() + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":00";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...