This time I will show you how to make a Date objectCountdown function, what are the precautions for making a Date object countdown function, the following is a practical case, one Get up and take a look.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>倒计时动画</title> <style> p{ text-align:center; height:100px; line-height:100px; } </style> <script> window.onload = function(){ setInterval(FreeTime,1000); } function FreeTime(){ var curTime = Date.now(); var endTime = new Date("2017-10-26 16:00:00"); var allFreeSeconds = (endTime-curTime)/1000; if(allFreeSeconds>0){ var freeDay = Math.floor(allFreeSeconds/(24*60*60)); var freeHour = Math.floor(allFreeSeconds/(60*60) % 24); var freeMinute = Math.floor(allFreeSeconds/60 % 60); var freeSecond = Math.floor(allFreeSeconds%60); document.getElementById("nowTime").innerHTML = "剩余"+freeDay+"天"+freeHour+"时"+freeMinute+"分"+freeSecond+"秒"; } else{ document.getElementById("nowTime").innerHTML = "已结束"; } } </script> </head> <body> <p> <span id="nowTime"></span> </p> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How SpringJDBC operates data in batches
How el-upload uploads Excel files
The above is the detailed content of How to create countdown function on Date object. For more information, please follow other related articles on the PHP Chinese website!