doulu8341 2015-03-22 04:53
浏览 37
已采纳

PHP DateTime对象的奇怪(?)行为

I am trying to run the following

$d = "2015-Mar-22";
$dsd = DateTime::createFromFormat('Y-M-d H:i:s', $d . " 00:00:00");
$ds = strtotime($dsd->date);

and get

PHP Notice:  Undefined property: DateTime::$date in php shell code on line 1

However, if I call var_dump($dsd) before converting to a unix timestamp I get the correct answer:

echo strtotime($dsd->date);

1427007600

Am I missing something here?

  • 写回答

1条回答 默认 最新

  • duanlujiaji10335 2015-03-22 05:35
    关注

    You're attempting to use an undocumented property that is only ever made available due to a side effect.

    ->date being available is actually a side-effect of support for var_dump()


    If you just want a timestamp use $dsd->getTimestamp() instead of strtotime($dsd->date).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统