2024-10-04 04:53:36 | 我爱编程网
我爱编程网(https://www.52biancheng.com)小编还为大家带来php 指定时间退后或提前N个月的函数怎么写的相关内容。
/**以上就是php中两个时间相减怎么得到年数全部内容了,了解更多相关信息,关注我爱编程网。更多相关文章关注我爱编程网:www.52biancheng.com
* 返回某个时间几月前或及月后的时间戳
* @$datetime 指定时间戳
* @$num 增减月份(1,-2)
* @return datetime
*/
public static function getEveryMonth($datetime,$num){
$year_month = date("Y-m",$datetime);
$time_day = date("d",$datetime);
$H = date("H",$datetime);
$i = date("i",$datetime);
$s = date("s",$datetime);
if($num>0){
$act = "+".abs($num)." month";
}else{
$act = "-".abs($num)." month";
}
$time = strtotime($act,strtotime($year_month));
$time_str = date("Y-m-d",$time);
if(date("t",$time)>$time_day){
$return_time = mktime($H,$i,$s,date("m",$time),date("d",$time),date("Y",$time));
}else{
$return_time = mktime($H,$i,$s,date("m",$time),date("t",$time),date("Y",$time));
}
return $return_time;
}
2025-02-01 20:24:39
2024-01-05 14:11:24
2025-02-10 15:19:48
2025-01-28 17:58:32
2024-11-22 05:08:01
2024-09-10 08:50:00