php – 计算两个日期时间之间的差异
发布时间:2020-12-13 13:28:42 所属栏目:PHP教程 来源:网络整理
导读:我正在使用 PHP和MySQL,并希望计算两个日期时间之间的日期时间差.我有一个消息表,在该表中createdate是一个字段.我想以1天2小时前的格式找出当前日期的日期和时间差异.最好的方法是什么? 使用PHP的内置日期函数: ?php $start_time = "Y-m-d H:i:s"; // fil
我正在使用
PHP和MySQL,并希望计算两个日期时间之间的日期时间差.我有一个消息表,在该表中createdate是一个字段.我想以1天2小时前的格式找出当前日期的日期和时间差异.最好的方法是什么?
使用PHP的内置日期函数:
<?php $start_time = "Y-m-d H:i:s"; // fill this in with actual time in this format $end_time = "Y-m-d H:i:s"; // fill this in with actual time in this format // both of the above formats are the same as what MySQL stores its // DATETIMEs in $start = new DateTime($start_time); $interval = $start->diff(new DateTime($end_time)); echo $interval->format("d days h hours"); > DateInterval documentation (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |