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');
     
  • 相关阅读:
    《梦断代码》阅读笔记01
    linux c netcdf 安装
    Windows CE中的进程和线程
    VC做任务管理器涉及到的函数
    curl_easy_getinfo() -- 从 curl 句柄里获得附加信息
    libcurl programming
    动态内存申请函数选择(realloc、malloc 、alloca、 calloc)
    C++: byte和int的相互转化
    8位灰度图像BMP的保存
    BMP图像的结构及读写和灰度化
  • 原文地址:https://www.cnblogs.com/mingforyou/p/2980304.html
Copyright © 2011-2022 走看看