In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how JavaScript uses Date to achieve a simple countdown. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Introduction
The Date object, which is the object that operates on the date and time. The Date object manipulates dates and times only through methods. Date, like Array in js, is a special object with its own special methods.
The syntax for creating a Date object:
The var myDate=new Date () / / Date object automatically saves the current date and time to its initial value.
Before we get the countdown, let's take a look at how to get the current time!
Function time () {var oDate = new Date (); var year = oDate.getFullYear (); var month = oDate.getMonth () + 1; var dDate = oDate.getDate (); var day = oDate.getDay (); var house = oDate.getHours (); var minu = oDate.getMinutes (); var sec = oDate.getSeconds (); switch (day) {case 1: day = 'Monday'; break; case 2: day = 'Tuesday'; break; case 3: day = 'Wednesday'; break Case 4: day = 'Thursday'; break; case 5: day = 'Friday'; break; case 6: day = 'Saturday'; break; case 0: day = 'Sunday'; break;} function double (t) {if (t < 10) {t ='0' + t;} return t } document.body [XSS _ clean] = year + 'year + month +' month + dDate + 'day' + day +''+ double (house) +':'+ double (minu) +':'+ double (sec);} time (); setInterval (time,1000)
Get the countdown
1. Realize the countdown function
2. The countdown end button can be clicked, but cannot be clicked before.
Example code:
Untitled document 0 days 00: 00: 00 # btn {text-decoration: none; display: block; width: 100px; height: 35px; background: # ccc; text-align: center; line-height: 35px; color: # 666;} # btn.btn {background: red; color: # fff; font-size: 20px; font-weight: bold;} is about to start! Var oLt = document.getElementById ("lastTime"); var oBtn = document.getElementById ("btn"); time (); var timer = setInterval (time, 1000); function time () {var endTime = new Date ('2017-01-13 var nowTime = new Date (); var splus = endTime.getTime ()-nowTime.getTime (); / / days, minutes and seconds if (splus)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.