How much time is the distance between js and a certain point in time

  • 2020-03-26 21:24:36
  • OfStack

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cn"> 
<head> 
<title> Is the 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> 
</head> 
<body> 
<div id="thenceThen"></div> 
</body> 

</html> 

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

Var date1 = new Date(1381741113671);

See below for parameter transfer (background parameters can also be received) :

There are five parameter forms 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 that in the last form, the parameter represents the number of milliseconds between the time to be created and the GMT time of January 1, 1970. The meanings of various functions are as follows:

Month: December, December, December, December, December, December

MTH: an integer for a month, from (January) to (December)

Dd: represents the days of the month, from 1 to 31

Yyyy: the year represented by four digits

Hh: hours, from 0 (midnight) to 23 (11 PM)
Mm: minutes, integers from 0 to 59

Ss: number of seconds, integers from 0 to 59

Ms: a number of milliseconds, an integer greater than or equal to 0

Such as:
 
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); 

Related articles: