Javascript outputs the current time in real time, and javascript outputs the current time in real time.
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 current time in due time
Function CurentTime (divID) {var curTime = new Array (); var now = new Date (); var week = ['day', 'yi', '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 );}
Usage:
Assume that there is a div whose id is time on the page, then:
<script language="javascript">CurentTime('time');</script>
The above is all the content of this article. I hope you will like it.