![](/img/trans.png)
[英]Get PHP date automatically hour, minute and second but user selects day, month, year
[英]Get the year, month week, day, hour, minute, second interval on two dates in PHP
如何在php上的两个日期上获取年,月,周,日,时,分,秒间隔?
例如:
date1 = 2015-9-24
date2 = 2015-12-25
输出:
3 months and 1 day left
多谢你们。
请尝试php diff
$date1 = new DateTime("2015-9-24");
$date2 = new DateTime("2015-12-25");
$interval = $date1->diff($date2);
echo "Result " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";
echo "Result " . $interval->days . " days ";
尝试这个
$a1 = new DateTime('2015-9-24');
$a2 = new DateTime('2015-12-25');
$interval = $a2->diff($a1);
$interval->format('%m months');
您正在使用PHP date_diff()函数
$date1=date_create("2013-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.