日期在php中的日期差异? [英] Date Difference in php on days?

查看:22
本文介绍了日期在php中的日期差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种快速的方法来计算 php 中的日期差异?例如:

Is there a quick way to calculate date difference in php? For example:

$date1 = '2009-11-12 12:09:08';
$date2 = '2009-12-01 08:20:11';

然后做一个计算,$date2减去$date1

And then do a calculation, $date2 minus $date1

我阅读了 php.net 文档,但没有运气.有什么快捷的方法吗?

I read php.net documentation, but no luck. Is there a quick way to do it?

推荐答案

strtotime 会将您的日期字符串转换为 unix 时间戳.(自 Unix 时代以来的秒数.

strtotime will convert your date string to a unix time stamp. (seconds since the unix epoch.

$ts1 = strtotime($date1);
$ts2 = strtotime($date2);

$seconds_diff = $ts2 - $ts1;

这篇关于日期在php中的日期差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆