In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "javascript how to dynamically display time", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "javascript how to dynamically display time" this article.
Javascript display time method: 1, use "new Date ()" to define the date object; 2, use the date object's getFullYear (), getMonth () and other methods to obtain the year, month, day, hour and second value and output; 3, use the setTimeout () method to refresh the time value once a second.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Javascript dynamic display time implementation code:
Dynamically display system date time function startTime () {var today=new Date (); / / define date object var yyyy = today.getFullYear (); / / return year var MM = today.getMonth () + 1 through the date object's getFullYear () method / / return the year var dd = today.getDate () through the date object's getMonth () method; / / return the year var hh=today.getHours () through the date object's getDate () method; / / return the hour var mm=today.getMinutes () through the date object's getHours method / / return minutes var ss=today.getSeconds () through the date object's getMinutes method; / / return seconds through the date object's getSeconds method / / if the value of the minute or hour is less than 10, add 0 to its value, for example, if the time is 03:20:09 in the afternoon, it shows 15:20:09 MM=checkTime (MM) Dd=checkTime (dd); mm=checkTime (mm); ss=checkTime (ss); var day / used to save the week (getDay () method gets the week number) if (today.getDay () = = 0) day = "Sunday" if (today.getDay () = = 1) day = "Monday" if (today.getDay () = = 2) day = "Tuesday" if (today.getDay ( ) = 3) day = "Wednesday" if (today.getDay () = = 4) day = "Thursday" if (today.getDay () = = 5) day = "Friday" if (today.getDay () = = 6) day = "Saturday" document.getElementById ('nowDateTimeSpan') [xss_clean] = yyyy+ "-" + MM + "-" + dd + "" + hh+ ":" + mm+ ":" + ss+ "" + day SetTimeout ('startTime ()', 1000); / / reload the startTime () method} function checkTime (I) {if (I) every second
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.