javascript - Using same code for chrome and firefox but get different results -
i have simple count down script. code works in chrome not firefox. in firefox displays nan chrome shows countdown ideas why happens?
function countdowntimer(time, name) { var counter = setinterval(function(){ var today = new date(); var expire = new date(time); var timeremains = expire - today; var days = math.floor(timeremains / (1000 * 60 * 60 * 24)); var hours = math.floor(timeremains / (1000 * 60 * 60)); var mins = math.floor(timeremains / (1000 * 60)); var secs = math.floor(timeremains / 1000); var dd = days; var hh = hours - days * 24; var mm = mins - hours * 60; var ss = secs - mins * 60; if (expire < today) { clearinterval(counter); document.getelementbyid(name).innerhtml = '<span class="expire">expire!</span>'; return; } else { if (dd < 10) { dd = "0" + dd; } if (hh < 10) { hh = "0" + hh; } if (mm < 10) { mm = "0" + mm; } if (ss < 10) { ss = "0" + ss; } document.getelementbyid(name).innerhtml = dd + ' : ' + hh + ' : ' + mm + ' : ' + ss; } }, 1000 ); } countdowntimer("2012-07-06 19:00:00", "time1");รข
the date() function doesn't seem work across browsers. try using setutc functions on it, so:
today.setutcfullyear(2012); today.setutchours(19, 0, 0, 0);
update: date() constructor fine on browsers, not when "improper" string used. try this:
var today = new date(2012,6,7,19,0,0)
Comments
Post a Comment