var timeobj=function(){
var add0=function(m){return m<10?'0'+m:m }
return {
format:function(time,type) {
var year=time.getFullYear();
var month=time.getMonth()+1;
var day=time.getDate();
var hour=time.getHours();
var minute=time.getMinutes();
var second=time.getSeconds();
if(!type||type==='second'){
return year+"-"+add0(month)+"-"+add0(day)+' '+add0(hour)+':'+add0(minute)+':'+add0(second);
}else if(type==='day'){
return year+"-"+add0(month)+"-"+add0(day);
}else if(type==='year'){
return year;
}
}
}
}
var time=timeobj().format(new Date(),'day');
alert(time)
js时间格式化方法
最新推荐文章于 2024-05-21 10:56:13 发布