js获取当前日期时间补零

阅读更多
function getNowFormatDate()
    {
       var day = new Date();
       var Year = 0;
       var Month = 0;
       var Day = 0;
       var Hour =0;
       var Minute = 0;
       var Second = 0;
       
       var CurrentDate = "";
       //初始化时间
       Year       = day.getFullYear();
       Month      = day.getMonth()+1;
       Day        = day.getDate();
       Hour       = day.getHours();
       Mintue     = day.getMinutes();
	   Second     = day.getSeconds();
       
       CurrentDate += Year + "/";
       if (Month >= 10 ){
        CurrentDate += Month + "/";
       }else{
        CurrentDate += "0" + Month + "/";
       }
       if (Day >= 10 ){ 
        CurrentDate += Day + " ";;
       }else{
        CurrentDate += "0" + Day + " ";;
       }
	   if(Hour>=10){
		   CurrentDate += Hour + ":";
	   }else{
		   CurrentDate += "0"+ Hour + ":";
	   }
	   if(Mintue>=10){
		   CurrentDate += Mintue + ":";
	   }else{
		   CurrentDate += "0"+ Mintue + ":";
	   }
	   if(Second>=10){
		   CurrentDate += Second ;
	   }else{
		   CurrentDate += "0"+ Second ;
	   }
       return CurrentDate;
    }

 

你可能感兴趣的:(js获取当前日期时间补零)