使用PHP获取两个时间/日期之间的差异? [英] Getting the difference between two time/dates using php?

查看:135
本文介绍了使用PHP获取两个时间/日期之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用php找出d-m-Y H:i(14-04-2009 12:15)格式的两个日期之间以分钟为单位的时差吗?

I am wanting to find out the time difference in minutes between two dates which is in the format d-m-Y H:i (14-04-2009 12:15) using php?

推荐答案

使用strtotime()将时间解析为时间戳,然后简单地从另一个中减去一个.

Parse the times into timestamps using strtotime() and then simply subtract one from the other.

之后,您可以使用数学函数来获取分钟数,天数等等.

After that you can get the number of minutes, days and so on by using math functions.

例如:

// $date1 and $date2 are given
// the difference is in seconds
$difference = strtotime($date1) - strtotime($date2);

// getting the difference in minutes
$difference_in_minutes = $difference / 60;

参考: strtotime()

这篇关于使用PHP获取两个时间/日期之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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