码迷,mamicode.com
首页 > 其他好文 > 详细

formatDate 格式化日期 ,给小于10的月日,加0,如01 02 03

时间:2016-04-28 12:16:49      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

var months=["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug","Sep","Oct", "Nov", "Dec"];
function formatDate(time){
    if(!time){
        return "";
    }

    if(typeof time==‘number‘){
        var d=new Date(time);
        var dStr = "";
        var mStr = "";
        if(d.getDate()<10){
            dStr = "0"+d.getDate();
        }else{
            dStr = d.getDate();
        }
        if(d.getMonth()<9){ //month should +1
            mStr = "0" + (d.getMonth()+1);
        }else{
            mStr = (d.getMonth()+1);
        }
        return d.getFullYear()+‘-‘+mStr+‘-‘+dStr;
    }
    else{

        return time;
    }
}

 

formatDate 格式化日期 ,给小于10的月日,加0,如01 02 03

标签:

原文地址:http://www.cnblogs.com/bravolove/p/5441912.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!