zoukankan      html  css  js  c++  java
  • js时间处理

    function CurentTime()
    { 
        var now = new Date();
       
        var year = now.getFullYear();       //
        var month = now.getMonth() + 1;     //
        var day = now.getDate();            //
       
        var hh = now.getHours();            //
        var mm = now.getMinutes();          //
       
        var clock = year + "/";
       
        if(month < 10)
            clock += "0";
       
        clock += month + "/";
       
        if(day < 10)
            clock += "0";
           
        clock += day + " ";
       
        if(hh < 10)
            clock += "0";
           
        clock += hh + ":";
        if (mm < 10) clock += '0'; 
        clock += mm; 
        return(clock); 
    } 
    
    function CurentTime2()
    { 
        var now = new Date();
       
        var year = now.getFullYear();       //
        var month = now.getMonth() + 1;     //
        var day = now.getDate();            //
       
        var hh = now.getHours();            //
        var mm = now.getMinutes();          //
        var ss = now.getSeconds();
        
        var clock = year + "/";
       
        if(month < 10)
            clock += "0";
       
        clock += month + "/";
       
        if(day < 10)
            clock += "0";
           
        clock += day + " ";
       
        if(hh < 10)
            clock += "0";
           
        clock += hh + ":";
        if (mm < 10) clock += '0'; 
        clock += mm + ":"; 
        
        if (ss < 10) clock += '0';
        clock += ss;
        
        return(clock); 
    } 
    
    function formate_time(str){
           var time = new Date(str);
        var year = time.getFullYear();       //
        var month = time.getMonth() + 1;     //
        var day = time.getDate();            //
       
        //var hh = time.getHours();            //时
        //var mm = time.getMinutes();          //分
       
        var clock = year + "/";
       
        if(month < 10)
            clock += "0";
       
        clock += month + "/";
       
        if(day < 10)
            clock += "0";
           
        clock += day;
        return(clock); 
    }
    
    function formate_time2(str){
           var time = new Date(str);
        var year = time.getFullYear();       //
        var month = time.getMonth() + 1;     //
        var day = time.getDate();            //
       
        var hh = time.getHours();            //
        var mm = time.getMinutes();          //
        var ss = time.getSeconds();
         
        var clock = year + "/";
       
        if(month < 10)
            clock += "0";
       
        clock += month + "/";
       
        if(day < 10)
            clock += "0";
           
        clock += day + " ";
        if(hh < 10)
            clock += "0";
           
        clock += hh + ":";
        if (mm < 10) clock += '0';
        clock += mm + ":"; 
        
        if (ss < 10) clock += '0';
        clock += ss;
        return(clock); 
    }
    
    function formate_time3(str){
           var time = new Date(str);
        var year = time.getFullYear();       //
        var month = time.getMonth() + 1;     //
        var day = time.getDate();            //
       
        var hh = time.getHours();            //
        var mm = time.getMinutes();          //
       // var ss = time.getSeconds();
         
        var clock = year + "/";
       
        if(month < 10)
            clock += "0";
       
        clock += month + "/";
       
        if(day < 10)
            clock += "0";
           
        clock += day + " ";
        if(hh < 10)
            clock += "0";
           
        clock += hh + ":";
        if (mm < 10) clock += '0'; 
        clock += mm;
        //clock += mm + ":"; 
        
        //if (ss < 10) clock += '0';
        //clock += ss;
        return(clock); 
    }
    Date.prototype.format = function(format)
    {
     var o = {
     "M+" : this.getMonth()+1, //month
     "d+" : this.getDate(),    //day
     "h+" : this.getHours(),   //hour
     "m+" : this.getMinutes(), //minute
     "s+" : this.getSeconds(), //second
     "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
     "S" : this.getMilliseconds() //millisecond
     }
     if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));
     for(var k in o)if(new RegExp("("+ k +")").test(format))
     format = format.replace(RegExp.$1,
     RegExp.$1.length==1 ? o[k] :
     ("00"+ o[k]).substr((""+ o[k]).length));
     return format;
    }
     
    日期格式化
    var d = new Date();
    d.format('yyyy-MM-dd');
     
  • 相关阅读:
    小学生学python(六)类与函数
    Windows 10 搭建 Flask
    CentOS 8 上安装 python3
    6_7 selenium使用代理IP
    6_6 模拟浏览器的前进后退&窗口句柄切换
    6_5 selenium操作cookie
    6_4 行为链
    6_3 selenium操作表单元素
    6_2 selenium定位元素的方法
    6_1 selenium 安装与 chromedriver安装
  • 原文地址:https://www.cnblogs.com/mingforyou/p/2980304.html
Copyright © 2011-2022 走看看