jquery 获取当前系统时间

    // 递归刷新系统时间
    getCode();
    function getCode(){
        i = self.setInterval("countdown()", 1000);
    }
    function countdown() {
      var myDate = new Date();
        //获取当前年
        var year=myDate.getFullYear();
        //获取当前月
        var month=myDate.getMonth()+1;
        //获取当前日
        var date=myDate.getDate(); 
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();  
        var now=year+'-'+getNow(month)+"-"+getNow(date)+" "+getNow(h)+':'+getNow(m)+":"+getNow(s);
        // 赋值给展示时间
        $('#Times').html('系统时钟:'+now);
    }
    // 获取当前时间
    function getNow(s) {
      return s < 10 ? '0' + s: s;
    }



 

你可能感兴趣的:(js(jquery))