zoukankan      html  css  js  c++  java
  • Date日期基础

     Date 对象

     Date 对象用于处理日期和时间。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            body{ background: #272822;}
            .date{ font-family: helvetica,arial,sans-serif; font-size: 70px; color: #ccc; margin: 40px auto; width: 700px; text-align: center; }
        </style>
    </head>
    <body>
    <div class="date">
        
    </div>
    <script>
    // Date 对象
    
    // Date 对象用于处理日期和时间。
    
    // 创建一个日期对象
    var currDate = new Date();
    
    // 获取当前年份
        currDate.getFullYear();
    // 获取当前月份(月份需要加1)
        currDate.getMonth()+1;                
    // 获取当前天数
        currDate.getDate();
    
    // 获取当前星期数(0代表星期日,1代表星期一,以此类推)
        currDate.getDay();
    
    // 获取当前小时数
        currDate.getHours();
    // 获取当前分钟数
        currDate.getMinutes();
    // 获取当前秒数
        currDate.getSeconds();
    
    // 将日期对象转换为字符串
        currDate.toString();
    
    
    //时间补零
    function toDou(n){
        if (n<10) {
            return '0'+n;
        }else{
            return ''+n;
        }
    }
    var dateHtml = document.getElementsByTagName('div')[0];
    setInterval(function(){
        var date = new Date();
        var day = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
        var currDate = date.getFullYear()+''+(date.getMonth()+1)+''+date.getDate()+''+'<br/>'+toDou(date.getHours())+':'+toDou(date.getMinutes())+':'+toDou(date.getSeconds())+ day[date.getDay()];
        dateHtml.innerHTML = currDate;
    },1000);
        
    </script>
    </body>
    </html>
  • 相关阅读:
    Linux下文件的基本操作
    conpot_usage简要说明
    const声明常量以及特点
    let变量声明以及声明特性
    盒子模型
    文本样式
    行间距
    字体的其他样式
    字体分类
    字体样式
  • 原文地址:https://www.cnblogs.com/jasontoyell/p/4752464.html
Copyright © 2011-2022 走看看