简体   繁体   English

PHP-DateTime->添加无法正常工作。 说DateInterval格式错误

[英]PHP - DateTime->add not working. Says DateInterval format is wrong

I've been struggling for a few hours on an error that I'm sure it's silly, but I can't find to solve it. 我已经为一个错误确定挣扎了几个小时,我确信这是愚蠢的,但是我找不到解决的方法。

My idea is to create a DateTime of (00:00:00), in order to add to it in a loop 4:30 hours per $i. 我的想法是创建一个(00:00:00)的DateTime,以便将其循环添加到每个$ i 4:30小时。

$saldo_funcionario = new DateTime('00:00:00');
for ($i=0; $i<$value; $i++) {
    $tempo_dia_funcionario = new DateInterval('PT4H30I');
    $saldo_funcionario->add($tempo_dia_funcionario);
}

The error message is: 错误消息是:

Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct(): Unknown or bad format (PT4H30I)' 
DateInterval->__construct('PT4H30I') #1 {main} on line 75

Where am I missing? 我在哪里想念?

$tempo_dia_funcionario = new DateInterval('PT4H30I');

Should be: 应该:

$tempo_dia_funcionario = new DateInterval('PT4H30M');

Notice 'M' instead of 'I'. 注意“ M”而不是“ I”。

http://php.net/manual/en/dateinterval.construct.php http://php.net/manual/en/dateinterval.construct.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM