本文操作环境:Windows10系统、php7.1版、Dell G3电脑
1、利用strtotime函数将时间格式化为时间戳
strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。
语法为:
strtotime('年-月-日 时:分:秒')
示例如下:
<?php
echo(strtotime('2022-04-13 12:25:00'));
?>
输出结果:
2、将两个时间戳相减,获取两个时间的时间差
3、将获取的时间差除以86400就是两个时间相差的天数
示例如下:
<?php
$time1=strtotime('2022-04-13 12:25:00');
$time2=strtotime('2022-04-15 12:25:00');
$diff_seconds = $time2 - $time1;
$diff_days = $diff_seconds/86400;
echo($diff_days . "天");
?>
输出结果:


![晴川云Minecraft Wiki教程:初始资源[ ],晴川云](https://baike.qcidc.com/wp-content/uploads/2025/09/20250919082238992-u_3160511210_2061549918fm_253fmt_autoapp_138f_JPEG.jpeg)







暂无评论内容