JS distance to a certain point in time is how to implement code _javascript skills

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Positive Timing </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<style type= "Text/css" >
#thenceThen {font-size:2em;}
</style>
<script type= "Text/javascript" language= "JavaScript" >
function Thencethen () {
var date1 = new Date (1381741113671);
var totalsecs= (New Date ()-date1)/1000;
var days=math.floor (TOTALSECS/3600/24);
var Hours=math.floor ((totalsecs-days*24*3600)/3600);
var Mins=math.floor ((totalsecs-days*24*3600-hours*3600)/60);
var Secs=math.floor ((totalsecs-days*24*3600-hours*3600-mins*60));
if (days!= 0) {
document.getElementById ("Thencethen"). innertext= "Answer time:" +days+ "Day" +hours+ "hours" +mins+ "minutes" +secs+ "seconds";
}else if (hours = = 0 && mins = 0) {
document.getElementById ("Thencethen"). innertext= "Answer time:" +secs+ "seconds";
}else if (hours = = 0 && mins!= 0) {
document.getElementById ("Thencethen"). innertext= "Answer time:" +mins+ "minutes" +secs+ "seconds";
}else if (hours!= 0) {
document.getElementById ("Thencethen"). innertext= "Answer time:" +hours+ "hours" +mins+ "minutes" +secs+ "seconds";
}
}
var clock;
Window.onload=function () {
Clock=self.setinterval ("Thencethen ()", 500);
}
</script>
<body>
<div id= "Thencethen" ></div>
</body>


=========================================================================================================

Above, var date1 = new Date (1381741113671);

Parameter passes are below (also receive background parameters):

The following 5 kinds of parameter form are:
Copy Code code as follows:

New Date ("Month dd,yyyy hh:mm:ss");
New Date ("Month dd,yyyy");
New Date (YYYY,MTH,DD,HH,MM,SS);
New Date (YYYY,MTH,DD);
New Date (MS);

Note the last form, which represents the number of milliseconds to create and the difference between GMT time January 1, 1970. The meanings of the various functions are as follows:

Month: Month name in English, from January to December

MTH: Month by integer, from (January) to 11 (December)

DD: Represents the day ordinal of one months, from 1 to 31

YYYY: four-digit year

HH: Hours, from 0 (midnight) to 23 (11 o'clock in the evening)
MM: Number of minutes, integers from 0 to 59

SS: Number of seconds, integers from 0 to 59

MS: Number of milliseconds, integer greater than or equal to 0

Such as:
Copy Code code as follows:

New Date ("January 12,2006 22:19:35");

New Date ("January 12,2006");

New Date (2006,0,12,22,19,35);

New Date (2006,0,12);

New Date (1137075575000);

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.