日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

PHP实现指定时间的n月之前的这一天的两种算法

發布時間:2023/12/15 综合教程 26 生活家
生活随笔 收集整理的這篇文章主要介紹了 PHP实现指定时间的n月之前的这一天的两种算法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/***根據$endtime,返回指定$monthes月之前的日*/function severalMonthAgo($endtime,$monthes){if (!$endtime) {	return false;}if (!is_int($monthes) || $monthes <=0) {	return false;}$m = date("m",$endtime);$y = date("Y",$endtime);$d = date("d",$endtime);$year = floor($monthes/12);$monthes_mod = $monthes%12;if($year == 0){//<12個月	if($m < $monthes){		//當前月份小于n月前		$res_y = $y-1;		$res_m = 12-($monthes-$m);		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d<$t){			$res_d = $d;		}else{			$res_d = $t;		}	}elseif($m == $monthes){		$res_y = $y-1;		$res_m = 12;		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d$monthes){		$res_y = $y;		$res_m = $m-$monthes;		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d0){	$y = $y-$year;	$monthes = $monthes_mod;	if($m < $monthes){		//當前月份小于n月前		$res_y = $y-1;		$res_m = 12-($monthes-$m);		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d<$t){			$res_d = $d;		}else{			$res_d = $t;		}	}elseif($m == $monthes){		$res_y = $y-1;		$res_m = 12;		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d$monthes){		$res_y = $y;		$res_m = $m-$monthes;		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d<$t){		$res_d = $d;		}else{			$res_d = $t;		}	}}return strtotime($res_y."-".$res_m."-".$res_d);}/***根據$endtime,返回指定$monthes月之前的日*/function severalMonthAgoEx($endtime,$monthes){if (!$endtime) {	return false;}if (!is_int($monthes) || $monthes 0;//$monthes_mod =0或>0或if ($year>0) {	if ($monthes_mod>0) {		$m_diff = 12+$m-$monthes_mod;		$m_diff_div = floor($m_diff/12);		$m_diff_mod = $m_diff%12;		if ($m_diff_div > 0) {			$res_y = $y;			$res_m = $m_diff_mod;		}elseif ($m_diff_div == 0) {			$res_y = $y -1;			$res_m = $m_diff_mod;		}	}elseif ($monthes_mod==0) {		//整除		$res_y = $y;		$res_m = $m;			}}elseif ($year == 0) {	$m_diff = 12+$m-$monthes_mod;	$m_diff_div = floor($m_diff/12);	$m_diff_mod = $m_diff%12;	if ($m_diff_div > 0) {		$res_y = $y;	}elseif ($m_diff_div == 0) {		$res_y = $y -1;	}	$res_m = $m_diff_mod;}$t = date("t",strtotime($res_y."-".$res_m."-01"));if($d<$t){	$res_d = $d;}else{	$res_d = $t;}return strtotime($res_y."-".$res_m."-".$res_d);}

登錄后復制

總結

以上是生活随笔為你收集整理的PHP实现指定时间的n月之前的这一天的两种算法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。