php 计算时间的年月日
生活随笔
收集整理的這篇文章主要介紹了
php 计算时间的年月日
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 /**
2 * 計算時間的年月日
3 * 2016-07-12
4 */
5 function diffDate($date1,$date2){
6 $datestart= date('Y-m-d',strtotime($date1));
7 if(strtotime($datestart)>strtotime($date2)){
8 $tmp=$date2;
9 $date2=$datestart;
10 $datestart=$tmp;
11 }
12 list($Y1,$m1,$d1)=explode('-',$datestart);
13 list($Y2,$m2,$d2)=explode('-',$date2);
14 $Y=$Y2-$Y1;
15 $m=$m2-$m1;
16 $d=$d2-$d1;
17 if($d<0){
18 $d+=(int)date('t',strtotime("-1 month $date2"));
19 $m--;
20 }
21 if($m<0){
22 $m+=12;
23 $y--;
24 }
25 if($Y == 0){
26 return $m.'個月'.$d.'天';
27 }elseif($Y == 0 && $m == 0){
28 return $d.'天';
29 }else{
30 return $Y.'年'.$m.'個月'.$d.'天';
31 }
32 }
33
34 $catdata="1986-09-28"; //計算時間
35 echo diffDate($catdata,date('Y-m-d',time()));
?
轉(zhuǎn)載于:https://www.cnblogs.com/Dong-Ge/articles/5664776.html
總結(jié)
以上是生活随笔為你收集整理的php 计算时间的年月日的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cent OS 7安装redis
- 下一篇: SAS系统窗口命令