面试题之(js实现当年剩余时间倒计时程序)

时间:2022-11-20 07:05:16

js实现当年剩余时间倒计时程序,请看代码:

<script>
function counter() { var date = new Date(); var year = date.getFullYear(); var date2 = new Date(year, , , , , ); /*转换成秒*/
var time = (date2 - date) / ; var day = Math.floor(time / ( * * )) var hour = Math.floor(time % ( * * ) / ( * )) var minute = Math.floor(time % ( * * ) % ( * ) / ); var second = Math.floor(time % ( * * ) % ( * ) % ); var str = year + "年还剩" + day + "天" + hour + "时" + minute + "分" + second + "秒"; console.log(str); } window.setInterval("counter()", );
</script>

打印出来的效果图如下:

面试题之(js实现当年剩余时间倒计时程序)

一个简易的当前年份剩余时间倒计时小程序就用JS实现了。