zoukankan      html  css  js  c++  java
  • js HTML 年月日星期 时间的

    
    

    效果格式:2019 年 04 月 13 日 星期六 13 24 : 49
    上面的类名有多余的 因为这是之前项目中的 方便以后使用
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>time</title>
        </head>
        <body>
             <div class="right-currentTime-logOut">
                    <span class="year fontDigi"></span>
                     <span class="separator"></span>
                     <span class="month fontDigi"></span>
                     <span class="separator "></span>
                     <span class="day fontDigi"></span>
                     <span class="separator "></span> 
                     <span class="currentDay-week"></span>
                     <span class="hour fontDigi"></span> 
                     <span class="separator">:</span>
                     <span class="minute fontDigi"></span>
                     <span class="separator">:</span>
                     <span class="second fontDigi"></span>
            </div>
            <script type="text/javascript">
                
                
                document.addEventListener('DOMContentLoaded', function () {
                    var _years = document.querySelector('.year');
                    var _months = document.querySelector('.month');
                    var _days = document.querySelector('.day');
                    var _week = document.querySelector('.currentDay-week');
                    var _hours = document.querySelector('.hour');
                    var _minutes = document.querySelector('.minute');
                    var _seconds = document.querySelector('.second');
                    function setText(){
                        var date = new Date();
                        var years = date.getFullYear(),
                            months =date.getMonth() + 1,
                            days = date.getDate();
                            weeks = date.getDay();
                        var hours = date.getHours(),
                            minutes = date.getMinutes();
                           seconds = date.getSeconds();
                        _years.innerHTML = years;
                        if(months < 10){
                            _months.innerHTML =String(0) + String(months);
                        }else{
                            _months.innerHTML =  months;
                        };
                        if(days < 10){
                            _days.innerHTML =String(0) + String(days);
                        }else{
                            _days.innerHTML = days;
                        };
                        if(weeks == 1){
                            _week.innerHTML = '星期一';
                        }else if(weeks == 2){
                            _week.innerHTML = '星期二';
                        }else if(weeks == 3){
                            _week.innerHTML = '星期三';
                        }else if(weeks == 4){
                            _week.innerHTML = '星期四';
                        }else if(weeks == 5){
                            _week.innerHTML = '星期五';
                        }else if(weeks == 6){
                            _week.innerHTML = '星期六';
                        }else{
                            _week.innerHTML = '星期日';
                        };
                        
                        if(hours < 10){
                            _hours.innerHTML =String(0) + String(hours);
                        }else{
                            _hours.innerHTML = hours;
                        };
                        
                        if(minutes < 10){
                            _minutes.innerHTML =String(0) + String(minutes);
                        }else{
                            _minutes.innerHTML = minutes;
                        };
                        if(seconds < 10){
                            _seconds.innerHTML =String(0) + String(seconds);
                        }else{
                            _seconds.innerHTML = seconds;
                        };
                    }
                    setText();
    //定时器 setInterval(
    function () { setText(); }, 1000); }); </script> </body> </html>

  • 相关阅读:
    ios web 媒体查询兼容
    Linux python 虚拟环境管理
    three.js 纹理动画实现
    three.js 在模型上移动相机
    three.js 模型拖动之DragControls控制器
    three.js 添加html内容、文本
    微信公众号对接记录
    事务的日志
    事务的隔离级别
    事务中的锁
  • 原文地址:https://www.cnblogs.com/toughy/p/10700818.html
Copyright © 2011-2022 走看看