JS获取当前时间实时显示

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>
head>

<body>
<div id="111">div>
body>
html>
<script>
//获取当前时间函数
setInterval('showtime()',100);
function showtime()
{
    var year,month,day,hour,minute,second;
    var now;
    var today = new Date();
    var week = today.getDay();//获取星期几
    switch(week)
    {
        case 0 :
        {
          week = '星期日';
          break;
        }
        case 1 :
        {
          week = '星期一';
          break;
        }
        case 2 :
        {
          week = '星期二';
          break;
        }
        case 3 :
        {
          week = '星期三';
          break;
        }
        case 4 :
        {
          week = '星期四';
          break;
        }
        case 5 :
        {
          week = '星期五';
          break;
        }
        case 6 :
        {
          week = '星期六';
          break;
        }
    }
    year = today.getFullYear();
    month = today.getMonth()+1;
    day = today.getDate();
    hour = today.getHours();
    minute = today.getMinutes();
    second = today.getSeconds();
    now = '现在是'+year+''+month+''+day+''+week+''+hour+''+minute+''+second+'';
    document.getElementById('111').innerHTML = now;
}
script>

 

转载于:https://www.cnblogs.com/Itwonderful/p/5679380.html

你可能感兴趣的:(xhtml)