JavaScript to achieve real-time output of the current time _javascript skills

Source: Internet
Author: User

Recently, there is a Web page to output the current time, accurate to time and minutes, but also timely changes. Baidu looked for, did not find suitable, so they wrote a, collection, easy to use later.

JS timely output The current time

function Curenttime (divid) { 
  var curtime=new Array (); 
  var now=new Date (); 
  var week=[' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; 
  var year=now.getfullyear ();   Year 
  var month=now.getmonth () +1;   Month 
  var day=now.getdate ();      Day 
  var hh=now.gethours ();      When 
  var mm=now.getminutes ();     Divided into 
  var sc=now.getseconds ();     Second 
  var wk=now.getday ();       Zhou 
  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[' SC ']=sc<10? ' 0 ' +sc:sc; 
  curtime[' wk ']= ' week ' +week[wk]; 
  curtime=curtime[' year ']+ ' +curtime[' month ']+ ' month ' +curtime[' Day ']+ ' th ' + ' ' +curtime[' wk ']+ ' ' +curtime[' ' hh ']+ ': ' + curtime[' mm ']+ ': ' +curtime[' SC ']; 
  document.getElementById (divid). Innerhtml= ' Today is: ' +curtime; 
  SetTimeout (' Curenttime (\ ' +divid+ ') ', 1000); 
} 

How to use:

Suppose a div with an ID named time exists on the page:

 
 

The above mentioned is the entire content of this article, I hope you can enjoy.

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.