Home  >  Article  >  Web Front-end  >  js displays the current date, time and day of the week_javascript skills

js displays the current date, time and day of the week_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:35:321898browse

JavaScript gets the current date and time and displays the day of the week. The specific code is as follows:

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script type="text/javascript" src="/jquery/1.7.0/jquery.min.js"></script> 
<script type="text/javascript"> 
function currentTime(){ 
  var d=new Date(),str=''; 
  str+=d.getFullYear()+'年'; 
  str+=d.getMonth() + 1+'月'; 
  str+=d.getDate()+'日'; 
  str+=d.getHours()+'时'; 
  str+=d.getMinutes()+'分'; 
  str+= d.getSeconds()+'秒'; 
  return str; 
} 
setInterval(function(){$('#time').html(currentTime)},1000); 
</script> 
</head> 
<body> 
<div id="time"></div> 
</body> 
</html> 

How to dynamically display the current date and time and the day of the week on a web page:

function showTime(){ 
  var show_day=new Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日'); 
  var time=new Date(); 
  var year=time.getYear(); 
  var month=time.getMonth(); 
  var date=time.getDate(); 
  var day=time.getDay(); 
  var hour=time.getHours(); 
  var minutes=time.getMinutes(); 
  var second=time.getSeconds(); 
  month<10&#63;month='0'+month:month; 
  month=month+1; 
  hour<10&#63;hour='0'+hour:hour; 
  minutes<10&#63;minutes='0'+minutes:minutes; 
  second<10&#63;second='0'+second:second; 
  var now_time='当前时间:'+year+'年'+month+'月'+date+'日'+' '+show_day[day-1]+' '+hour+':'+minutes+':'+second; 
  document.getElementById('showtime').innerHTML=now_time; 
  setTimeout("showTime();",1000); 
} 

There is a lot of content on the Internet about this. There are js to get the current date and time while displaying the day of the week, js to get the current time and the time of the week, etc., which are all of great reference value. I hope everyone will read more similar articles and use similar methods. Be proficient in it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn