当前位置:首页 > 开发 > Web前端 > JavaScript > 正文

js获取当前日期时间补零

发表于: 2014-02-09   作者:coldg   来源:转载   浏览:
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;
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获取当前日期时间补零

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号