距离2020年一月30号还剩。。。
Posted 汪洋是大大的海
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了距离2020年一月30号还剩。。。相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> <style> #con { width: 500px; height: 200px; border: 2px solid fuchsia; margin: 30px auto; } #con1 { width: 500px; height: 100px; line-height: 100px; font-size: 20px; } #con2 { width: 500px; height: 100px; line-height: 100px; font-size: 30px; color: darkturquoise } </style> </head> <body> <div id="con"> <div id="con1">距离过年还剩:</div> <div id="con2"></div> </div> <script> var con, con1, con2; con = document.getElementById("con") con1 = document.getElementById("con1") con2 = document.getElementById("con2") function auto() { var time time = new Date() newtime = new Date(2020, 0, 30) tt = newtime.getTime() - time.getTime() console.log(tt) day = Math.floor(tt / 1000 / 60 / 60 / 24) hours = Math.floor((tt - day * 24 * 60 * 60 * 1000) / 1000 / 60 / 60) minutes = Math.floor((tt - day * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60) seconds = Math.floor((tt - day * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000) millioseconds = Math.floor((tt - day * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000 - seconds * 1000)) //console.log(day+"天"+hours+"小时"+minutes+"分"+seconds+"秒") con2.innerHTML = day + "天" + hours + "小时" + minutes + "分" + seconds + "秒" + millioseconds + "毫秒" // console.log( time.getTime()/1000/60/60/24/365) } setInterval(auto, 1) </script> </body> </html>
以上是关于距离2020年一月30号还剩。。。的主要内容,如果未能解决你的问题,请参考以下文章
写了一个时间处理的类,能将人类时间转换成距离公元零年一月一日秒数(时间戳),同时支持时间戳转换成日期时间