欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

原生js實現(xiàn)日期計算器功能

 更新時間:2017年02月17日 10:42:48   作者:火紅橘子  
這篇文章主要為大家詳細介紹了原生js實現(xiàn)日期計算器功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了日期計算器的具體實現(xiàn)代碼,供大家參考,具體內(nèi)容如下

日期計算器html代碼片段:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>日期計算器</title>
 <script type="text/javascript" src="date_calc.js"></script>
</head>
<body>
<br><br>
<b>推算幾天后的日期:</b>
<br>
 和
<input size="8" id="SY" value="2016">年
<input size="4" id="SM" value="11">月
<input size="4" id="SD" value="16">日
(缺省為今天)
<br>相差
<input size="8" id="decday" value="100">天
(輸入負數(shù)則往前計算)
<br>是:
<span id="result1"></span>
<br>
<input type=button value="計算" onclick="cala()">

<br>


<b>計算日期差:</b>
<br>

  <input size="8" id="SY2" value="2016">年
<input size="4" id="SM2" value="11">月
<input size="4" id="SD2" value="16">日

<br>
和 <input size="8" id="SY3" value="2017" >年
<input size="4" id="SM3" value="1">月
<input size="4" id="SD3" value="1">日
<br>相差:
<span id="result2"></span>天
<br>
<input type=button value="計算" onclick="calb()">
<br>
</body>

</html>

date_calc.js代碼片段:

var hzWeek= new Array("日","一","二","三","四","五","六","日");

//獲取星期
function cweekday(wday)
{return hzWeek[wday];}


function cala()
{
y=document.getElementById("SY").value;
m=document.getElementById("SM").value;
d=document.getElementById("SD").value;
ddd=document.getElementById("decday").value;

ttt=new Date(y,m-1,d).getTime()+ddd*24000*3600;

theday=new Date();
theday.setTime(ttt);

document.getElementById("result1").innerHTML=theday.getFullYear()+"年"+(1+theday.getMonth())+"月"+theday.getDate()+"日"+"星期"+cweekday(theday.getDay());


}


function calb()
{

y2=document.getElementById("SY2").value;
m2=document.getElementById("SM2").value;
d2=document.getElementById("SD2").value;


y3=document.getElementById("SY3").value;
m3=document.getElementById("SM3").value;
d3=document.getElementById("SD3").value;


day2=new Date(y2,m2-1,d2);
day3=new Date(y3,m3-1,d3);

document.getElementById("result2").innerHTML=(day3-day2)/86400000;


}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論