1、當前年的時間戳
2、當前月的時間戳
3、當前日的時間戳
4、明年的開始時間戳
5、下月的開始時間戳
6、明日的開始時間戳
7、當前時間戳
函數代碼:
/**
* 獲取時間戳
* $Ymd = Y 年
* $Ymd = m 月
* $Ymd = d 日
* $Ymd = NULL 當前時間戳
* $xia = true 是否取下次開始時間戳:取下年開始時間戳 或者下月開始時間戳 或者明日開始時間戳
*/
function getTime($Ymd=NULL,$xia=false){
if($Ymd=='Y' && $xia==true){
//取下個年度開始時間戳
return strtotime((date('Y',time())+1).'-01-01 00:00:00');
}
else if($Ymd=='Y'){
//取本年度開始時間戳
return strtotime(date('Y',time()).'-01-01 00:00:00');
}
else if($Ymd=='m' && $xia==true){
//取下個月度開始時間戳
$xiayue_nianfen = date('Y',time());
$xiayue_yuefen = date('m',time());
if($xiayue_yuefen==12){
$xiayue_nianfen += 1; //如果月份等於12月,那麼下月年份+1
$xiayue_yuefen = 1; //如果月份等於12月,那麼下月月份=1月
}
else{
$xiayue_yuefen += 1; //如果月份不是12月,那麼在當前月份上+1
}
return strtotime($xiayue_nianfen.'-'.$xiayue_yuefen.'-01 00:00:00');
}
else if($Ymd=='m'){
//取本月度開始時間戳
return strtotime(date('Y-m',time()).'-01 00:00:00');
}
else if($Ymd=='d' && $xia==true){
//取明日開始時間戳
return strtotime(date('Y-m-d',time()).' 00:00:00')+86400;
}
else if($Ymd=='d'){
//取今日開始時間戳
return strtotime(date('Y-m-d',time()).' 00:00:00');
}
else{
//取當前時間戳
return time();
}
}
調用代碼:
getTime('Y'); //當前年的時間戳
getTime('m'); //當前月的時間戳
getTime('d'); //當前日的時間戳
getTime('Y',true); //明年的時間戳
getTime('m',true); //下月的時間戳
getTime('d',true); //明日的時間戳
getTime(); //當前的時間戳