发布网友 发布时间:2023-10-09 09:57
共2个回答
热心网友 时间:2024-02-03 04:19
<script type="text/javascript">
// 生成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;
}
console.log("data-:"+"yd");console.log(_yd());
/** * 计算当前时间距元旦时间间隔 */
function yd_cal() {
var ipt = document.getElementById('time');
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) + "秒"
}
window.onload=yd_cal;
</script>
</head>
<body>
<div style=" width:500px; height:300px;background:#ccc no-repeat;">
<input type="text" id="time" name="time" style="padding:10px;" />
</div>
</body>
//我用上述代码在chrome上运行是有数字显示的
热心网友 时间:2024-02-03 04:20
右键标题点击与测试服务器比较(w)
选择自己要用的浏览器应用程序