Without further ado, see the code below
PC:
1.html page:
<div class="aTime"> <em id="t_d"></em> <em id="t_h"></em> <em id="t_m"></em> <em id="t_s"></em> </div>
2.js:
<script type="text/javascript"> function GetRTime(){ var end = "<?php echo $info['end_date']; ?>"+" 23:59:59"; var EndTime = new Date (end); var NowTime = new Date(); var t =EndTime.getTime() - NowTime.getTime(); var d=0; var h=0; var m=0; var s = 0; if(t>=0){ d=Math.floor(t/1000/60/60/24); h=Math.floor(t/1000/60/60%24); m=Math.floor(t/1000/60%60); s=Math.floor(t/1000%60); } document.getElementById("t_d").innerHTML = d; document.getElementById("t_h").innerHTML = h; document.getElementById("t_m").innerHTML = m; document.getElementById("t_s").innerHTML = s; } setInterval(GetRTime,1000); </script>
The above code is giving error in safari because:
The Safari browser in IOS5 and above (excluding IOS5) can correctly interpret the date object of new Date('2013-10-21') in Javascript.
However, the interpretation of new Date('2013-10-21') in Safari in the IOS5 version is incorrect, and the Safari in IOS5 always returns "Invalid Date".
Later, I found information on the Internet. It turned out that the lower version of Safari explained that the object of new Date ('2013-10-21') is different. Safari in IOS5 does not support this writing method.
And it supports the writing method of new Date('2013','10','21'), which can solve the problem of "Invalid Date" and return a Javascript Date.
If you want Safari in IOS5 to parse new Date() correctly, you must write like this
new Date('2013/10/21'); 或者 var d = new Date(date);d = d.getFullYear() > 0 ? d : new Date(Date.parse(date.replace(/-/g, "/")));