JavaScript 网页中实现一个计算当年还剩多少时间的倒数计时程序
程序员文章站
2022-06-01 15:03:38
看到网上这个程序 发现了处错误这里改正了一下:
function counter() {
var date = new date();
var y...
看到网上这个程序 发现了处错误这里改正了一下:
function counter() { var date = new date(); var year = date.getfullyear(); var date2 = new date(year, 11, 30, 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);
这是我自己写的
var odatenow = new date(); var oyear = odatenow.getfullyear(); var odateend = new date(); odateend.setfullyear(oyear+1); odateend.setmonth(0); odateend.setdate(0); odateend.sethours(0); odateend.setminutes(0); odateend.setseconds(0); function update(){ var odatenow = new date(); var itime = odateend.gettime()-odatenow.gettime(); var iremain = itime/1000; var iday=parseint(iremain/86400); iremain%=86400; var ihour=parseint(iremain/3600); iremain%=3600; var imin=parseint(iremain/60); iremain%=60; var isec=parseint(iremain); document.write(oyear+"年还剩"+iday+"天"+ihour+"时"+imin+"分"+isec+"秒"); } setinterval(function(){ update() },1000);
这两个方法的秒数有出处
以上所述是小编给大家介绍的javascript 网页中实现一个计算当年还剩多少时间的倒数计时程序,希望对大家有所帮助