问题与PHP DateTime的date属性 [英] Issue with PHP DateTime's date property

查看:190
本文介绍了问题与PHP DateTime的date属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个好奇的问题。



以下代码产生错误。

  $ startDate = new约会时间(); 
// print_r($ startDate);
$ i = strpos($ startDate-> date,'');
$ this-> startByTime = substr($ startDate-> date,0,$ i)。'T'.substr($ startDate-> date,$ i + 1)。'000Z'

注意:未定义的属性:DateTime :: $日期在C:\xampp\htdocs\hspace\buildschedule.php在线..

而且date属性似乎未定义。作为 $ this-> strartByTime ='T000Z'在所有这些结束。



现在如果我取消注释print_r语句一切正常。任何人都可以向我解释。

解决方案

没有 - > date 属性在 DateTime对象中,这就是PHP为什么抱怨 $ startDate-> date



也许你的意思是 $ startDate->格式('r')或类似的


I have a curious problem.

The following code generates an error.

$startDate = new DateTime();
//  print_r($startDate);
$i = strpos($startDate->date,' ');
$this->startByTime = substr($startDate->date,0,$i).'T'.substr($startDate->date,$i+1).'.000Z';

Notice: Undefined property: DateTime::$date in C:\xampp\htdocs\hpace\buildschedule.php on line..

And the date property seems to be undefined. as $this->strartByTime = 'T000Z' at the end of all this.

Now if I uncomment the print_r statement all works fine. Can anyone explain this to me.?

解决方案

There is no ->date attribute in the DateTime object, which is why PHP's complaining about $startDate->date.

Perhaps you mean $startDate->format('r') or similar?

这篇关于问题与PHP DateTime的date属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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