js HTML 年月日星期 时间的

Posted Miss--Yang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>

 

以上是关于js HTML 年月日星期 时间的的主要内容,如果未能解决你的问题,请参考以下文章

js显示当前日期时间和星期几

js中如何根据日期算出星期几

年月日 时分秒 星期 农历 实时刷新 时间插件

java中根据当前年月日和星期 获取到下个星期X的年月日

//输出电脑系统的年月日星期以及时间

js根据年月计算出这个月有多少周