JS显示具体时间

版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!


恰饭广告




<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
    #showtime{
        font-size: 20px;
        color: red;
        width: 450px;
        height: 30px;
        border: 1px solid black;
        margin: auto;
        line-height: 30px;
        text-align: center;
    }
    </style>
</head>
<body>
    <div id="showtime"></div>
    <script>
        function showtime (){
     var time = new Date();
     var week;
     switch (time.getDay()){
         case 1: week="星期一"; break;
         case 2: week="星期二"; break;
         case 3: week="星期三"; break;
         case 4: week="星期四"; break;
         case 5: week="星期五"; break;
         case 6: week="星期六"; break;
         default:week="星期天"; break;
     }
     var years = time.getFullYear();
       if(years<10){
        year="0"+years;
     }
     var month = time.getMonth()+1;
      if(month<10){
         month="0"+month;
     }
     var day = time.getDate();
       if(day<10){
        day="0"+day;
     }
     var hours =time.getHours();
        if(hours<10){
        hours="0"+hours;
     }
     var minutes =time.getMinutes();
        if(minutes<10){
        minutes="0"+minutes;
     }
     var seconds=time.getSeconds();
        if(seconds<10){
        seconds="0"+seconds;
     }
     var str ="当前日期为:"+ years+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+" "+week;
     document.getElementById("showtime").innerHTML= str;
    }
    setInterval("showtime()",100);
    </script>
</body>
</html> 

原文链接:https://www.idaobin.com/archives/226.html

让我恰个饭吧.ヘ( ̄ω ̄ヘ)

支付宝 ——————- 微信
图片加载中图片加载中



恰饭广告

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

1 + = 8