时间戳的制作

时间戳的制作在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间戳的制作</title>

    <style>
        h2{
            width: 400px;
            margin: 100px auto;
            text-align: center;
        }
    </style>

</head>
<body>
    <pre>
        作业:封装一个函数,能正常输出日期和时间,如2017年12月13日星期三15:04:04

    求出,今天距离XXXXX发生的时期过去了多少天,多少小时,分钟
     1937年12月13日     10:01:00
 
    </pre>

        
            <h2 id="res"></h2>
        
    <script>
     var res=   document.getElementById("res");
     var stringDate="";
     var upToDate="";
     var times=getDate();




     stringDate =times.year+"年"+times.month+"月"+times.date+"日\t"+times.weeks+"\t "+times.hours+":"+times.miutes+":"+times.seconds;
     console.log(stringDate); 



        var toMinu=(times.miutes-1);
        // toMinu.style.color=red;
        setInterval(function(){
            upToDate="今天距XXXXX发生已有:<br>"+"<b style='color:red'>"+(((times.year-1938)*365)+18+monthDay(times.month,times.date,times.year))+"</b>"+"天"+"<b style='color:red'>"+(times.hours-10)+"</b>"+"小时"+"<b style='color:red'>"+toMinu+"</b>"+"分钟";
            // console.log(upToDate);
            res.innerHTML=upToDate;
     
        },600);
           
        function monthDay(month,d,year){
                var tian=0;
            switch(month*1){

            case 12:tian+=30;
            case 11:tian+=31;
            case 10:tian+=30;
            case 9:tian+=31;
            case 8:tian+=31;
            case 7:tian+=30;
            case 6:tian+=31;
            case 5:tian+=30;
            case 4:tian+=31;
            case 3:
                if(year%4===0&&year%100!==0||year/400===0)
                {
                    tian+=29;
                }else{
                    tian+=28;
                }
            case 2:tian+=31;
            case 1:tian+=d;
             
            
            return tian;
        }
    }
    


            function getDate(){
                var date=new Date();

                var y=date.getFullYear();
                var m=date.getMonth();
                var myDate=date.getDate();
                var week=date.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;
                }
                var hours=date.getHours();
                var minus=date.getMinutes();
                var secon=date.getSeconds();
                var minu=date.getMilliseconds();
               
                return {
                        year:addZero(y),
                        month:addZero(m),
                        date:addZero(myDate),
                        weeks:addZero(week),
                        hours: addZero(hours),
                        miutes:addZero(minus),
                        seconds:addZero(secon),

                };
            }


            //加〇
            function addZero(a){
               return a<10? "0"+a:a;
            }
    </script>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值