简体   繁体   English

date_diff() 期望参数 2 是 DateTimeInterface,布尔值在第 234 行给出

[英]date_diff() expects parameter 2 to be DateTimeInterface, boolean given at line 234

I get the following error and I don't know how to solve it..我收到以下错误,我不知道如何解决它..

date_diff() expects parameter 2 to be DateTimeInterface, boolean given at line 234 date_diff() 期望参数 2 是 DateTimeInterface,布尔值在第 234 行给出

This is the code:这是代码:


public static function timeLeft($datetime, $out_in_array=false, $html = false) {
      $intervalo = date_diff(date_create(), date_create($datetime)); ----------   LINE 234
        $out = $intervalo->format("%d d, %H h, %i m"); 

        if(!$out_in_array) {
            if($html) {
                return $intervalo->invert ? "<b class='red'>-$out</b>" : "<b class='green'>$out</b>";
            }

            return $intervalo->invert ? "-$out" : $out;
        }

        return [
            'days' => $intervalo->d,
            'hours' => $intervalo->h,
            'minutes' => $intervalo->i,
            'seconds' => $intervalo->s,
        ];
    } 

You have an error because date_diff() must have 2 param.你有一个错误,因为 date_diff() 必须有 2 个参数。 Your code:您的代码:

$intervalo = date_diff(date_create(), date_create($datetime));

date_create() < dont have a param. date_create() < 没有参数。 so you have just second param.所以你只有第二个参数。 correct >date_create($datetime)正确 >date_create($datetime)

How use correctly:如何正确使用:

$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.

相关问题 Date_diff() 期望参数 2 为 DateTimeInterface,Boolean Given - Date_diff() expects parameter 2 to be DateTimeInterface, Boolean Given date_diff()期望参数2为DateTimeInterface,给定字符串 - date_diff() expects parameter 2 to be DateTimeInterface, string given date_diff() 期望参数 1 为 DateTimeInterface,字符串给定 - date_diff() expects parameter 1 to be DateTimeInterface, string given 我需要用 PHP 时间戳减去 mySQL 时间戳。 获取“date_diff() 期望参数 1 为 DateTimeInterface,给定数组”错误 - I need to subtract a mySQL timestamp with a PHP timestamp. Getting a “date_diff() expects parameter 1 to be DateTimeInterface, array given” error date_format() 期望参数 1 为 DateTimeInterface,给定布尔值 - date_format() expects parameter 1 to be DateTimeInterface, boolean given DateTime :: diff()期望参数1为DateTimeInterface,给定字符串 - DateTime::diff() expects parameter 1 to be DateTimeInterface, string given PHP date_format()期望参数1为DateTimeInterface - PHP date_format() expects parameter 1 to be DateTimeInterface date_format 期望参数 1 为 DateTimeInterface/ 致命错误:调用成员函数 add() on boolean in - date_format expects parameter 1 to be DateTimeInterface/ Fatal error: Call to a member function add() on boolean in 检索错误ate_diff()期望参数2为DateTimeInterface - Retrieving error ate_diff() expects parameter 2 to be DateTimeInterface date_format() 期望参数 1 为 DateTimeInterface,给定 null(视图:/home/vagrant/code/blog/resources/views/singlePost.blade.php) - date_format() expects parameter 1 to be DateTimeInterface, null given (View: /home/vagrant/code/blog/resources/views/singlePost.blade.php)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM