/**//获取当天日期 返回 yyyy-mth-day 的格式
* 对日期格式的转换
* @param 无--返回当天
* '+num' 返回当天的后几天
* '-num' 返回当天的前num天
* @returns yyyy-mth-day 的格式
*
*/
function getDate(){
var param = arguments,
date = new Date();
if(param.length==0){
return changeDateType(date);
}else if(param.length==1){
if(param[0].toString().indexOf("+")!="-1"){
var nowTime = date.getTime(),
preDate = param[0].substr(1,param[0].length-1),
preDateTime = Number(preDate)*24*60*60*1000;
nowTime = Number(nowTime)+preDateTime;
var newDate = new Date(nowTime);
return changeDateType(newDate);
}else if(param[0].toString().indexOf("-")!="-1"){
var nowTime = date.getTime(),
preDate = param[0].substr(1,param[0].length-1),
preDateTime = Number(preDate)*24*60*60*1000;
nowTime = Number(nowTime)-preDateTime;
var newDate = new Date(nowTime);
return changeDateType(newDate);
}else{
return null;
}
}
function changeDateType(date){
var year = date.getFullYear(),
mon = date.getMonth() < 9 ? '0'+(date.getMonth()+ 1) : date.getMonth() + 1 ,
day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate(),
nowDate = year+"-"+mon+"-"+day;
return nowDate;
}
}