精品源码
正文

网页中如何显示日期时间

来源:精品源码 时间:2012/11/14

网页中如何显示日期时间
实例如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
 function showDateTime()
 {
  var myDateTime=new Date();
  var myYears=myDateTime.getYear();
  var myMonths=myDateTime.getMonth()+1;
  var myDates=myDateTime.getDate();
  var myDays=myDateTime.getDay();
  myDays=("日一二三四五六").charAt(myDays);
  var myHours=myDateTime.getHours();
  myHours=(myHours<10)?("0"+myHours):(myHours);
  var myMinutes=myDateTime.getMinutes();
  myMinutes=(myMinutes<10)?("0"+myMinutes):(myMinutes);
  var mySeconds=myDateTime.getSeconds();
  mySeconds=(mySeconds<10)?("0"+mySeconds):(mySeconds);
  var txtDateTime=myYears+"年"+myMonths+"月"+myDates+"日 星期"+myDays+" "+myHours+":"+myMinutes+":"+mySeconds;
  document.getElementById("dateTime").innerHTML=txtDateTime;
  setTimeout("showDateTime()",1000);
 }
</script>

</head>

<body onload="showDateTime();">
 <span id="dateTime" style="color:black;font-style.:italic;font-size:14px;"></span>
 <!--可将这个sapn放在网页的任何位置-->
</body>

</html>

本文链接: http://www.webym.net/zhuanti/thred-1317.html