国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js 距離某一時(shí)間點(diǎn)時(shí)間是多少實(shí)現(xiàn)代碼

2019-11-20 21:53:37
字體:
供稿:網(wǎng)友
復(fù)制代碼 代碼如下:

<!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>正計(jì)時(shí)</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=" 答題時(shí)間:"+days+"天"+hours+"小時(shí)"+mins+"分鐘"+secs+"秒";
}else if (hours == 0 && mins == 0) {
document.getElementById("thenceThen").innerText=" 答題時(shí)間:"+secs+"秒";
}else if (hours == 0 && mins != 0) {
document.getElementById("thenceThen").innerText=" 答題時(shí)間:"+mins+"分鐘"+secs+"秒";
}else if (hours != 0) {
document.getElementById("thenceThen").innerText=" 答題時(shí)間:"+hours+"小時(shí)"+mins+"分鐘"+secs+"秒";
}
}
var clock;
window.onload=function(){
clock=self.setInterval("thenceThen()", 500);
}
</script>
</head>
<body>
<div id="thenceThen"></div>
</body>

</html>

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

上文中 var date1 = new Date(1381741113671);

參數(shù)傳遞見下方(也可接收后臺(tái)參數(shù)):

參數(shù)形式有以下5種:
復(fù)制代碼 代碼如下:

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);

需要注意最后一種形式,參數(shù)表示的是需要?jiǎng)?chuàng)建的時(shí)間和GMT時(shí)間1970年1月1日之間相差的毫秒數(shù)。各種函數(shù)的含義如下:

month:用英文表示月份名稱,從January到December

mth:用整數(shù)表示月份,從(1月)到11(12月)

dd:表示一個(gè)月中的第幾天,從1到31

yyyy:四位數(shù)表示的年份

hh:小時(shí)數(shù),從0(午夜)到23(晚11點(diǎn))
mm:分鐘數(shù),從0到59的整數(shù)

ss:秒數(shù),從0到59的整數(shù)

ms:毫秒數(shù),為大于等于0的整數(shù)

如:
復(fù)制代碼 代碼如下:

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);
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 榆社县| 泰和县| 沅江市| 鄂托克前旗| 南和县| 焦作市| 海南省| 海阳市| 安福县| 扶余县| 湖南省| 固阳县| 平果县| 晴隆县| 麻江县| 朝阳区| 凯里市| 宝清县| 高州市| 临沭县| 寿光市| 柳林县| 南陵县| 尼勒克县| 册亨县| 班戈县| 厦门市| 嘉黎县| 营口市| 明溪县| 胶南市| 东源县| 高陵县| 墨玉县| 柏乡县| 施甸县| 津南区| 平和县| 高密市| 沂源县| 嵊泗县|