How to use javascript to make a countdown to a certain time
Today, I would like to share with you how to use javascript to do a countdown to a certain time, the content is detailed, the logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.
Document
/ / time today
Window.setInterval (function () {
Var nowDate = new Date ()
/ / Monday time
Var tomorrowDate = new Date ("2021-12-22 08:00:00")
Var secStr = nowDate.getTime ()
Var secStr = tomorrowDate.getTime ()
Var sss = tomorrowDate-nowDate
Var sec = Math.floor (sss / 1000% 60)
Var min = Math.floor (sss / 1000 / 60% 60)
Var hour = Math.floor (sss / 1000 / 60 / 60% 24)
Var day = Math.floor (sss / 1000 / 60 / 60 / 24% 24)
Var yue = Math.floor (sss/1000/60/60/24)
Sec = sec < 10? "0" + sec: sec
Min = min < 10? "0" + min: min
Hour = hour < 10? "0" + hour: hour
Day = day < 10? "0" + day: day
/ / [xss_clean] (day)
/ / [xss_clean] (hour)
/ / [xss_clean] (min)
/ / [xss_clean] (sec)
Var shijian = "still away from class" + day + "days" + hour + "hours" + min + "minutes" + sec + "seconds"
Document.body [XSS _ clean] = shijian
/ / [xss_clean] (shijian)
})
These are all the contents of the article "how to use javascript to do a countdown to a certain time". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.