求出今天距离某一天过了多少时间

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<br>
<br>
<center>
<font color="ffaafa">
  <h2><b><font color="#FF0000">时间日期篇--距离某天时间</font></b></h2>
  </font>
  <hr width=300>
<br><br>

<!-- 案例代码开始 -->

<SCRIPT type="text/javascript">
<!-- [Step1]: 这里可以改变您的计时日期 -->
var  birthDay=new Date("2002-1-1");//january 01,2002
var now=new Date();
timeOld=(now.getTime()-birthDay.getTime());
//求出天数
sectimeOld=timeOld/1000;
per_day=24*60*60*1000;//每天多少毫秒
e_daysold=timeOld/per_day;//求出过了多少天,但是是浮点数
//Math.floor()数学函数,求一个浮点数的地板,就是求一个最接近它的整数,它的值小于或等于这个浮点数。
e_daysold=Math.floor(e_daysold);
//求出小时
e_hoursold=(timeOld-e_daysold*24*60*60*1000)/1000/60/60;
e_hoursold=Math.floor(e_hoursold);
//求出分钟
e_minutesold=(timeOld-e_daysold*24*60*60*1000-e_hoursold*60*60*1000)/60/1000;
e_minutesold=Math.floor(e_minutesold);
//求出秒数
e_secondsold=(timeOld-e_daysold*24*60*60*1000-e_hoursold*60*60*1000-e_minutesold*60*1000)/1000;
e_secondsold=Math.floor(e_secondsold);
document.write("距离2002年1月1日已经过了: "+e_daysold+"天"+e_hoursold+" 小时 "+
              e_minutesold+"分钟"+e_secondsold+"秒");
</SCRIPT>

<SCRIPT language=javascript>
//language=javascript的功能类似于type="text/javascript",但是建议写成type="text/javascript"
//document.write("2002年已经过去了"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒啦!");

</SCRIPT>

<!-- 案例代码结束 -->

</center>
</body>
</html>

posted @ 2016-05-20 09:33  坚哥威武  阅读(1156)  评论(0编辑  收藏  举报