Pure JavaScript enables real-time feedback of system time and javascript Real-Time

Source: Internet
Author: User

Pure JavaScript enables real-time feedback of system time and javascript Real-Time

Use javascript to feedback system time

Use knowledge

JavaScript HTML DOM

The setInterval () method in the html dom does not stop calling the function until clearInterval () is called or the window is closed. The ID value returned by setInterval () can be used as a parameter of the clearInterval () method.

SyntaxsetInterval(code,milliseconds)

Code -- code (can be a function)

Milliseconds -- the time (in milliseconds) that is called here)

Therefore, if we want to let the feedback system time go up, we only need to call the method once every 1000 milliseconds to make the display time move like an alarm clock.

setInterval(function(){myTimer()},1000)

New Date () // obtain the current time. toLocaleTimeString () // converts the time part of the Date object to a string based on the local time. getElementById ("clock") // returns the element with the specified ID. innerHTML = c; // return c to the specified Element

Code Section

<!DOCTYPE html>

Summary

The above section describes how to implement real-time feedback on the system time using pure JavaScript. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.