我正在尝试使用 ZF2 Doctrine ORM 模块保存数据,使用动态参数作为实体类名称并初始化其对象并使用来自 excel 表标题的动态值保存数据,
$time = \PHPExcel_Style_NumberFormat::toFormattedString($rowData[0][$key], 'hh:mm:ss');
$obj->$setter(\DateInterval::createFromDateString($this->secondsToTime(strtotime($time))));
$this->orm->persist($obj);
$this->orm->flush();
$this->secondsToTime(strtotime($time)) 以 4 小时 5 分 6 秒的格式返回时间
字段类型是时间,当我打印 $obj->getter() 时,它会打印:
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 0
[h] => 4
[i] => 5
[s] => 6
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] =>
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
但它不会将其值保存为数据库中的 4:05:06,而是保存 00:00:00。我尝试从这里回答