【发布时间】:2014-06-30 23:24:46
【问题描述】:
如果我取消评论print_r($dateTime),那么此语句工作正常echo $dateTime->date;
为什么会这样。请给我建议。
$current_date=date('Y-m-d H:i:s');
$dateTime = DateTime::createFromFormat("Y-m-d H:i:s", $current_date, (new DateTimeZone('UTC')));
$dateTime->setTimezone(new DateTimeZone('PST'));
//print_r($dateTime); //If I print object then below echo stmt is working
echo $dateTime->date;
出现跟随错误
Notice: Undefined property: DateTime::$date in C:\xampp\htdocs\datetime.php
【问题讨论】:
-
你的php版本是多少?
-
我的PHP版本是5.5.9
-
旁注:你根本不需要
date()。如果您使用DateTime,请坚持使用。混合使用不同的日期格式只会增加混乱。