date_diff()期望参数1为DateTimeInterface,给定字符串 [英] date_diff() expects parameter 1 to be DateTimeInterface, string given
本文介绍了date_diff()期望参数1为DateTimeInterface,给定字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了这个问题,我不知道该怎么办...
它们具有相同的格式
i got this problem and i don't know what to do... they have thesame format
$date_expire = '2014-08-06 00:00:00';
$date1 = date("Y-m-d G:i:s");
$date2 = date_create($date_expire);
$diff = date_diff($date1, $date2); //this line makes error..
推荐答案
因为传递字符串,而 date_diff 期望 datetime
对象,
Because you are passing string whereas date_diff expects datetime
object,
$date_expire = '2014-08-06 00:00:00';
$date = new DateTime($date_expire);
$now = new DateTime();
echo $date->diff($now)->format("%d days, %h hours and %i minuts");
演示 。
这篇关于date_diff()期望参数1为DateTimeInterface,给定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文