javascript 实现一个网页,然后计算出有多少剩余时间的倒计时程序

function counter() {

	var date = new Date();

	var year = date.getFullYear();

	var date2 = new Date(year, 12, 31, 23, 59, 59);

	/*转换成秒*/
var time = (date2 - date) / 1000; var day = Math.floor(time / (24 * 60 * 60)) var hour = Math.floor(time % (24 * 60 * 60) / (60 * 60)) var minute = Math.floor(time % (24 * 60 * 60) % (60 * 60) / 60); var second = Math.floor(time % (24 * 60 * 60) % (60 * 60) % 60); var str = year + "年还剩" + day + "天" + hour + "时" + minute + "分" + second + "秒"; console.log(str); } window.setInterval("counter()", 1000);

版权声明:本文博主原创文章。博客,未经同意不得转载。

上一篇:【公告】关于8.8MIP组件审核平台故障的说明


下一篇:eclipse run on server 时 报的错误APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!