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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php日期相减函数,倒计时函数_计算两个时间相差值_PHP函数

發布時間:2023/12/10 php 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php日期相减函数,倒计时函数_计算两个时间相差值_PHP函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

**PHP倒計時函數、求兩個日期時間之間相差的時間函數、計算時差函數_PHP函數筆記**

```php

/**

* 求兩個日期時間之間相差的時間

* (針對1970年1月1日之后,求之前可以采用泰勒公式)

* @param string $day1 2016-10-01 10:01:08

* @param string $day2 2020-10-01 10:01:08

* @return list

*/

function diffBetweenTwoDate($start_time, $end_time){

$start = strtotime($start_time);

$stop = strtotime($end_time);

if($start < $stop){

$total_days = ($stop-$start) / 86400;

$result['total_days'] = intval($total_days);

$result['year'] = 0;

$result['month'] = 0;

if($total_days < 7){//如果小于7天直接返回天數

$result['day'] = intval($total_days);

}elseif($total_days <= 31){//小于28天則返回周數,由于閏年2月滿足了

if($stop == strtotime($start_time.'+1 month')){

$result['month'] = 1;

}else{

//$w = floor($total_days / 7);

//$d = ($stop - strtotime($start_time.'+'.$w.' week')) / 86400;

//$result['week'] = $w;

//$result['day'] = intval($d);

$result['day'] = intval($total_days);

}

}else{

$y= floor($total_days / 365);

if($y >= 1){//如果超過一年

$start = strtotime($start_time.'+'.$y.'year');

$start_time = date('Y-m-d',$start);

//判斷是否真的已經有了一年了,如果沒有的話就開減

if($start>$stop){

$start_time = date('Y-m-d',strtotime($start_time.'-1 month'));

$m = 11;

$y--;

}

$total_days = ($stop - strtotime($start_time)) / 86400;

}

if(isset($m)){

$w = floor($total_days / 7);

$d = $total_days-$w * 7;

}else{

$m = isset($m) ? $m : round($total_days / 30);

$stop >= strtotime($start_time.'+'.$m.'month') ? $m : $m--;

if($stop >= strtotime($start_time.'+'.$m.'month')){

$d = $w = ($stop-strtotime($start_time.'+'.$m.'month')) / 86400;

//$w = floor($w / 7);

//$d = $d - $w * 7;

}

}

$result['year'] = $y;

$result['month'] = $m;

//$result['week'] = $w;

$result['day'] = intval(isset($d) ? $d : 0);

}

$result['hours'] = intval((($stop - $start) % 86400) / 3600);

$result['min'] = intval(((($stop - $start) % 86400) % 3600) / 60);

$result['sec'] = ((($stop - $start) % 86400) % 3600) % 60;

}else{

$result['total_days'] = 0;

$result['year'] = 0;

$result['month'] = 0;

$result['day'] = 0;

$result['hours'] = 0;

$result['min'] = 0;

$result['sec'] = 0;

}

//return array_filter($result);

return $result;

}

```

返回字段**年、月、日、時、分、秒**

最后更新于?2019-07-20 16:39:20?并被添加「倒計時 php函數筆記」標簽,已有 14971 位童鞋閱讀過。

本站使用「署名 4.0 國際」創作共享協議,可自由轉載、引用,但需署名作者且注明文章出處

相關文章

總結

以上是生活随笔為你收集整理的php日期相减函数,倒计时函数_计算两个时间相差值_PHP函数的全部內容,希望文章能夠幫你解決所遇到的問題。

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