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');
 

 

posted @ 2013-03-25 10:47  残星  阅读(343)  评论(0编辑  收藏  举报