本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑php怎么计算时间相减差距几天实现思想:使用strtotime()函数将两个时间转为时间戳将两个时间戳相减,得到时间差将时间差除以一天的总秒数(24*60*60=864
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php怎么计算时间相减差距几天
实现思想:
使用strtotime()函数将两个时间转为时间戳
将两个时间戳相减,得到时间差
将时间差除以一天的总秒数(24*60*60=86400)
用floor()取整
实现代码:
<?php
header("Content-type:text/html;charset=utf-8");
//2022年1月1日 19点30分0秒
$time1=strtotime("2022-1-1");
//2022年7月7日 7点30分0秒
$time2=strtotime("2022-7-7");
$diff_seconds = $time2 - $time1;
$diff_days = floor($diff_seconds/86400);
echo "两个时间相差: ".$diff_days." 天";
?>
--结束END--
本文标题: php怎么计算时间相减差距几天
本文链接: https://www.lsjlt.com/news/1422.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0