zoukankan      html  css  js  c++  java
  • 常用javascript对象——Date对象

    创建 Date 对象的语法

    new Date();

    1:Date 对象属性

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script>
            //Date.prototype.方法名=function(){}为类添加方法
                Date.prototype.currentTime=function (){
                    var year = this.getFullYear();
                    var month = this.getMonth()+1;
                    month=month>10?month:"0"+month;
                    var dat =this.getDate();
                    dat=dat>10?dat:"0"+dat;
                    var week = this.getDay();
                    week="星期"+"日一二三四五六".charAt(week);
                    
                    var hour = this.getHours();
                    hour=hour>10?hour:"0"+hour;
                    var minute = this.getMinutes();
                    minute=minute>10?minute:"0"+minute;
                    var second = this.getSeconds();
                    second=second>10?second:"0"+second;
                    return year+"/"+month+"/"+dat+"/"+week+"  "+hour+":"+minute+":"+second;
                }
                function setTime(){
                    document.getElementById("time").innerHTML=new Date().currentTime();
                }
                window.onload=function(){
                    setTime();
                };
                setInterval("setTime()",1000);
        </script>
        </head>
        <body>
            <span id="time"></span>
        </body>
        
    </html>
  • 相关阅读:
    九九乘法表
    杨辉三角
    显示计算机界面
    完善3.2
    杨辉三角形
    100以内的素数
    九九乘法表
    杨辉三角
    九九乘法表
    杨辉三角形
  • 原文地址:https://www.cnblogs.com/lyxcode/p/9515810.html
Copyright © 2011-2022 走看看