Micro-letter Page countdown code (to solve Safari incompatible date problem) _javascript tips

Source: Internet
Author: User

Don't say much, please look at the following code

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 has an error in Safari because:

The Safari browser in the IOS5 version (without IOS5) correctly interprets the Date object for new date (' 2013-10-21 ') in JavaScript.

But in the IOS5 version, Safari explains that new date (' 2013-10-21 ') is not correct, and that IOS5 's safari is always returned with "Invalid date."

I later looked up the information on the Internet, which was originally a low version of Safari explaining the object of new Date (' 2013-10-21 '), which is not supported by Safari in IOS5,

And it's supported by the new date (' 2013 ', ' 10 ', ' 21 ') so that it can solve the "Invalid date" problem and return a JavaScript date back.

If you want safari in IOS5 to parse new Date correctly, you have to write this.

New Date (' 2013/10/21 '); or var d = new Date;d = D.getfullyear () > 0? D:new Date (Date.parse (Date.replace (/-/g, "/"));

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.