The number of days from the current time to a fixed date, such as: How many days before the page pops up to May 1, 2015

Source: Internet
Author: User
Tags date1

2015-03-28 17:46:05

<script>//gets the current system time Var now=new date ();//Gets May 1, 2015 time var date1=new date (' 2015/5/1 ');//The current date is the number of milliseconds from the initial date var s1= Now.gettime ();//May 1, 2015 number of milliseconds from the initial date var s2=date1.gettime ();//To May 1, 2015 How many milliseconds s3=s2-s1;//to May 1, 2015 How many days alert (' There is also ' +math.ceil (s3/(1000*60*60*24) + ' Day ') from May 1, 2015;  </script>

There are some books on the introduction of the parse, but now almost no use of the parse, almost all with gettime, but no matter which method, the idea of the problem is still unchanged

If you write more carefully:

<script>  //using the Date Date object to complete, the page shows how many days until May 1, 2015//Gets the current system time Var now=new Date ();//Get May 1, 2015 time var date1= New Date (' 2015/5/1 ');//The current date is the number of milliseconds from the initial date var s1=now.gettime ();//May 1, 2015 the number of milliseconds from the initial date var s2=date1.gettime ();/ The number of milliseconds to May 1, 2015 s3=s2-s1;//to May 1, 2015 How many days VAR Diff=math.ceil (s3/(1000*60*60*24)), if (diff>1) {alert (' Until May 1, 2015 there is ' +diff+ ' Day ');} else if (diff==1) {alert (' Tomorrow is May 1, 2015 ');} else if (diff==0) {alert (' Today is May 1, 2015 ');} Else{alert (' Silly, May 1, 2015 has passed! ');}  </script>

  

The number of days from the current time to a fixed date, such as: How many days before the page pops up to May 1, 2015

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.