PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php date 时间差大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

date 时间

时间第二个参数0 1970-01-01
时间第二个参数是负数 小于1970-01-01

日期比较

strtotime() 转为 时间戳
date("Y-m-d",strtotime("-1 day"));
date("Y-m-d",strtotime("-1 month"));
date("Y-m-d",strtotime("-1 year"));

时间差

$zero1 = strtotime(date("Y-m-d h:i:s"));
$zero2=strtotime ("2022-1-21 00:00:00");  //过年时间,不能写2014-1-21 24:00:00  这样不对 
$guonian=ceil(($zero2-$zero1)/86400); //60s*60min*24h   
echo "离过年还有<strong>$guonian</strong>天!"; 

//PHP计算两个时间差的方法 
$startdate="2021-12-12 11:40:00";
$enddate="2021-12-12 18:32:09";
$date=floor((strtotime($enddatE)-strtotime($startdatE))/86400);
$hour=floor((strtotime($enddatE)-strtotime($startdatE))%86400/3600);

$minute=floor((strtotime($enddatE)-strtotime($startdatE))%86400%3600/60);

$second=floor((strtotime($enddatE)-strtotime($startdatE))%86400%60);
echo $date."天<br>";
echo $hour."小时<br>";
echo $minute."分钟<br>";
echo $second."秒<br>";

大佬总结

以上是大佬教程为你收集整理的php date 时间差全部内容,希望文章能够帮你解决php date 时间差所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: