国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 邏輯算法 > 正文

PHP實(shí)現(xiàn)指定時(shí)間的n月之前的這一天的兩種算法

2020-03-22 19:27:37
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
  • /***根據(jù)$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個(gè)月	if($m < $monthes){		//當(dāng)前月份小于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<$t){			$res_d = $d;		}else{			$res_d = $t;		}	}elseif($m>$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;		}	}}elseif($year>0){	$y = $y-$year;	$monthes = $monthes_mod;	if($m < $monthes){		//當(dāng)前月份小于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<$t){			$res_d = $d;		}else{			$res_d = $t;		}	}elseif($m>$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);}/***根據(jù)$endtime,返回指定$monthes月之前的日*/function severalMonthAgoEx($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;$y -= $year;//$year =0或>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編程

    鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

  • 發(fā)表評(píng)論 共有條評(píng)論
    用戶(hù)名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 揭西县| 西乌珠穆沁旗| 长乐市| 松潘县| 林芝县| 长泰县| 景泰县| 贵德县| 长沙县| 出国| 泗洪县| 临朐县| 奇台县| 五峰| 五华县| 靖边县| 广灵县| 兴隆县| 边坝县| 鹿邑县| 白城市| 泽州县| 绥阳县| 密山市| 蒲江县| 定安县| 遂川县| 孟连| 定远县| 潞西市| 南汇区| 维西| 连州市| 西藏| 和林格尔县| 北辰区| 陆丰市| 龙陵县| 虎林市| 哈巴河县| 永泰县|