Heim  >  Artikel  >  Backend-Entwicklung  >  PHP实现指定时间的n月之前的这一天的两种算法

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

WBOY
WBOYOriginal
2016-06-23 13:57:37828Durchsuche

/***根据$endtime,返回指定$monthes月之前的日*/function severalMonthAgo($endtime,$monthes){if (!$endtime) {	return false;}if (!is_int($monthes) || $monthes $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){		$res_y = $y;		$res_m = $m-$monthes;		$t = date("t",strtotime($res_y."-".$res_m."-01"));		if($d0;//$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  <br> 
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn