我正在从一个laravel应用程序调用一个更新方法,不幸的是,一个错误的updated_at被插入了一个小时的增量,尽管两边的时区是相同的。你可以在这里看到源datetime的转储结果和另一边的查询结果之间的差异,有一个小时的差异:

下面是我用来调用遥控器的代码:
$updatedIntranet = new DateTime($stagesIntranet[$key]->updated_at);
$stageSiteValueIndex = array_keys($stagesSiteIds,$id);
echo('id : '. $id);
$updatedsite = new DateTime($stagesSite[$stageSiteValueIndex[0]]->updated_at);
$diffTimestamps = $updatedIntranet->getTimestamp() - $updatedsite->getTimestamp();
echo '------- updated intranet ---------<br />';
dump($stageIntranet->updated_at);
echo '-------- updated site --------<br />';
dump($stagesSite[$stageSiteValueIndex[0]]->updated_at);
echo '--------diff--------<br />';
// site must be updated
if( $diffTimestamps != 0)
{
dump('delta : '.$diffTimestamps);
$countUpdated++;
$stageIntranet->id = $stageIntranet->id_stages;
unset($stageIntranet->id_stages);
$stageIntranetCleanUTF8 = $this->utf8ize($stageIntranet->toArray());
$stageIntranetJson = json_encode($stageIntranetCleanUTF8,JSON_UNESCAPED_UNICODE);
$updateResponse = $client->put(
$this->updateTarget.'/'.$stageIntranet->id,
[
'json'=>[$stageIntranetJson],
]
);
dd($updateResponse->getBody()->getContents());
}所以下一次我启动代码增量应该是0,不幸的是,如你所见,总是有3600秒

发布于 2021-03-10 21:35:20
我得到了答案,自从Laravel 7以来,这是一个突破性的变化你必须在你的模型中覆盖默认的Datetime序列化,参见:https://laravel.com/docs/7.x/upgrade#date-serialization
https://stackoverflow.com/questions/66564192
复制相似问题