<html>
<head>
<title>cc-vue.js</title>
<style?type="text/css">
</style>
<script>
//?生成2019年元旦日期函數
function?_yd()?{
var?yd?=?new?Date();
//?2019?-?01-01
//?Year
yd.setYear(yd.getFullYear()?+?1);
//?Month
yd.setMonth(0);
//?Day
yd.setDate(1);
//?Time
yd.setHours(0,0,0,0);
return?yd;
}
/**
?*?計算當前時間距元旦時間間隔
?*/
function?yd_cal()?{
var?ipt?=?document.getElementById('ipt');
var?now?=?new?Date();
var?ts?=?_yd().getTime()?-?now.getTime();
var?_d?=?ts?/?(24?*?60?*?60?*?1000);
//?console.log('天:'?+?parseInt(_d));
var?_h?=?(_d?-?parseInt(_d))?*?24;
//?console.log('小時:'?+?parseInt(_h));
var?_m?=?(_h?-?parseInt(_h))?*?60;
//?console.log("分鐘:"?+?parseInt(_m));;
var?_s?=?(_m?-?parseInt(_m))?*?60;
//?console.log("秒:"?+?parseInt(_s));;
ipt.value?=?"?"?+?parseInt(_d)?+?"天?"?+?parseInt(_h)?+?":"?+?parseInt(_m)?+?":"?+?parseInt(_s)?+?""?
}
</script>
</head>
<body?style="margin:?20px;">
<div?style="width:?100%;?height:?40px;?background-color:?#fff">
<label?for="ipt"?style="font-size:?.8em">當前距元旦時間間隔:</label>
<input?type="text"?value=""?placeholder="元旦時間間隔"?disabled?id="ipt">
<input?type="button"?value="計算"?onclick="yd_cal()"?/>
</div>
</body>
</html>