欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

JavaScript使用setInterval实现天数倒计时以及本地时间

程序员文章站 2022-03-28 18:03:49
...
我们在之前的文章中我们给大家介绍了JavaScript中setInterval的使用详解,对于setInterval的认识相信小伙伴们都有自己的了解,那么我们今天继续给大家介绍下JavaScript使用setInterval实现天数倒计时以及本地时间的案例!

JavaScript使用setInterval实现天数倒计时以及本地时间

今天是<script type="text/javascript">var d = new Date(); 
document.write('<input type=\"hidden\" name=\"wd\" type=\"text\" value=\"'+ (d.getMonth()+1)+'月'+d.getDate()+'日'+ '\">'); 
document.write(d.getFullYear()+'年'+(d.getMonth()+1)+'月'+d.getDate()+'日'+' 星期'+'日一二三四五六'.charAt(new Date().getDay()));</script>。
2018年高考时间:2018-06-07 9:00:00,距离考试还有<script type="text/javascript" language="javascript" >
var bsDate=new Date('4/19/2018');
function getchaTime()
{
var date = new Date();
var start =bsDate.getTime() - date.getTime();
var startday = Math.floor(start/(1000 * 60 * 60 * 24));
if(startday > 0){ document.write("<span class='danger'>"+startday+"</span>天");
}else{
}
}
getchaTime();
window.setInterval('getchaTime()',3600000);

今天是2017年11月24日 星期五。
2018年高考时间:2018-06-07 9:00:00,距离考试还有194天

总结:

通过对本文的详细学习,相信很多小伙伴们对JavaScript中setInterval的使用有了进一步的认识和了解,希望对你的工作有所帮助!
相关推荐:

JavaScript中setInterval的使用详解


JS实现定时任务,每隔N秒请求后台setInterval定时和ajax请求


JS SetInterval 如何实现页面轮询教程

以上就是JavaScript使用setInterval实现天数倒计时以及本地时间的详细内容,更多请关注其它相关文章!