Js real-time acquisition of the current system time

Source: Internet
Author: User

Java code
1. <script language = "javascript" type = "text/javascript">
2. // use the jQuery page to load directly
3. $ (document). ready (function (){
4. fillDate ();
5 .});
6. // main Time Processing Method
7. function fillDate (){
8. // Date
9. var now = new Date (); // obtain the system Date, that is, Sat Jul 29 08:24:48 UTC + 0800 2006
10. var yy = now. getFullYear (); // year, that is, 2006
11. var mm = now. getMonth () + 1; // capture the month, that is, 07
12. var dd = now. getDate (); // truncate the day, that is, 29
13. var cal = yy + "." + mm + "." + dd;
14. // obtain the time
15. var hh = now. getHours (); // intercept the hour, that is, 8
16. var mm = now. getMinutes (); // capture minutes, that is, 34
17. var ss = now. getTime () % 60000;
18. // obtain the time. Because the time in the system is calculated in milliseconds, the second is obtained through an additional 60000.
19. ss = (ss-(ss % 1000)/1000; // then, the number of milliseconds is processed into seconds.
20. var clock = hh + ':'; // concatenate the obtained parts into a date and time.
21. if (mm <10) clock + = '0'; // string
22. clock + = mm + ':';
23. if (ss <10) clock + = '0 ';
24. clock + = ss;
25. // assign a value to the corresponding position of the page
26. $ (". date" 2.16.html (cal + "" + clock );
27. var timeID = setTimeout (fillDate, 1000 );
28 .}
29. </script>

Thanks to wucf2004, we have achieved new results by improving his methods.


From chenyanqing8899-163-com

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.