ITeye博客

JS时间格式化(短日期)

hsys · 2010-08-05 14:21 · JavaScript · Web前端 · Markdown

JS时间格式化(短日期),如new Date() 转成2010-08-05


function ChangeDateToString(DateIn){
    var Year = 0;
    var Month = 0;
    var Day = 0;	
    var CurrentDate = "";		
    Year  = DateIn.getFullYear();
    Month  = DateIn.getMonth()+1;
    Day  = DateIn.getDate();	
    CurrentDate = Year + "-";
    if (Month >= 10 ){
        CurrentDate = CurrentDate + Month + "-";
    } else{
        CurrentDate = CurrentDate + "0" + Month + "-";
    }
    if (Day >= 10 ){
        CurrentDate = CurrentDate + Day ;
    } else{
        CurrentDate = CurrentDate + "0" + Day ;
    }
    return CurrentDate;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。