【问题标题】:How to access date member variable from a returned array object如何从返回的数组对象中访问日期成员变量
【发布时间】:2012-12-18 20:10:44
【问题描述】:

我正在尝试使用 PHP 从 SQL 2008 数据库服务器获取当前日期/时间。 当我对返回变量进行转储时,我看到以下内容 -

array (size=1) <br />
  'current_date_time' =>  <br />
    object(DateTime)[1] <br />
      **public 'date' => string '2012-12-18 15:01:35' (length=19)** <br />
      public 'timezone_type' => int 3 <br />
      public 'timezone' => string 'UTC' (length=3) <br />

问题:如何仅访问“日期”变量?我尝试了以下但没有奏效:

return $row["current_date_time"]-&gt;date

【问题讨论】:

  • 没有工作”是什么意思:你收到错误了吗?
  • 是的,我得到一个错误,注意:未定义的属性:C:\wamp\www\cccac\cccac_functions.php 中的 DateTime::$date 在第 378 行

标签: php sql-server datetime


【解决方案1】:
$row["current_date_time"]->format('Y-m-d H:i:s');

应该做你需要的。看起来$row["current_date_time"] 是一个DateTime 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多