Js outputs current time in due time

Source: Internet
Author: User
Tags timestamp to date

Recently, the current time must be output on a website page, accurate to minutes and seconds, and must be changed in a timely manner. Baidu did not find a suitable one, so he wrote it and added it to his favorites for later use.

// Js outputs the current time function CurentTime (divID) {var curTime = new Array (); var now = new Date (); var week = ['day ', '1', '2', '3', '4', '5', '6']; var year = now. getFullYear (); // year var month = now. getMonth () + 1; // month var day = now. getDate (); // var hh = now. getHours (); // var mm = now. getMinutes (); // minute var SC = now. getSeconds (); // second var wk = now. getDay (); // week curTime ['Year'] = year; curTime ['month'] = month <10? '0' + month: month; curTime ['day'] = day <10? '0' + day: day; curTime ['hh'] = hh <10? '0' + hh: hh; curTime ['mm'] = mm <10? '0' + mm: mm; curTime ['scs'] = SC <10? '0' + SC: SC; curTime ['wk '] = 'Week' + week [wk]; curTime = curTime ['Year'] + 'Year' + curTime ['month'] + 'month' + curTime ['day'] + 'day' + ''+ curTime ['wk '] + ''+ curTime ['hh'] + ': '+ curTime ['mm'] +': '+ curTime ['scs']; document. getElementById (divID ). innerHTML = 'Today is: '+ curTime; setTimeout ('curenttime (\ ''+ divID +' \ ')', 1000 );}


// Assume that there is a div whose id is time on the page. <script language = "javascript"> CurentTime ('time'); </script>
Articles you may be interested in
  • Mysql converts unix timestamp to date format, and MySQL queries the current time
  • Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
  • JavaScript retrieves the current date and time and displays the day of the week at the same time
  • PHP obtains the current time and timestamp.
  • How to Use zlib to compress output content to speed up web page opening
  • Display the last modification time of the file in JavaScript
  • How to obtain the complete url address and parameters in javascript
  • Js to get the current mouse position, compatible with ie and firefox

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.