1 function formatDate(date){
2 if(date == null){
3 return;
4 }
5 date = new Date(date);
6 var Y=date.getFullYear()+'-',
7 M=(date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'-',
8 D=(date.getDate()<10?'0'+date.getDate():date.getDate())+'-',
9 h=(date.getHours()<10?'0'+date.getHours():date.getHours())+'-',
10 m=(date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes())+'-',
11 s=(date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds())+'-',
12 return Y+M+D+h+m+s;
13 }
//获取年,月,季,日时间
function getDate(str){
var date = new Date(),
year = date.getFullYear(),
month=date.getMonth(),
week =date.getDay() || 7,
day =date.getDate();
switch(str){
case 'day':
return new Date(year,month,day);
case 'week':
return new Date(year,month,day+1-week);
case 'month':
return new Date(year,month);
case 'season':
return new Date(year,parseInt(month/3)*3);
case 'year':
return new Date(year,0)
}
}