我正在尝试获取与MySQL中的数据相同的时区,但是JSON响应的回复时间不同。我尝试使用Carbon,但结果始终显示相同(与我的时区不同)。另外,我的时区在app.php
到'timezone' => 'Asia/Kuala_Lumpur'
中,以将数据存储为我所在的国家时区。
$todayentry = SensorTissue::whereDate('entryDate', Carbon::now()->setTimezone(config('app.timezone')))->get()->sortBy('entryDate');
$todayentry = json_decode($todayentry);
return $todayentry;
json响应的结果:
[{
"tsID": 10,
"entryDate": "2020-04-04T23:57:17.000000Z",
"sensorValue": 7
},
{
"tsID": 11,
"entryDate": "2020-04-04T23:57:34.000000Z",
"sensorValue": 6
}]
响应显示为2020-04-04T23:57:34.000000Z
在我的数据库中应为2020-04-05 07:57:34
。
尝试替换下面的代码行:
$todayentry = SensorTissue::whereDate('entryDate', Carbon::now()->setTimezone(config('app.timezone')))
->get()->sortBy('entryDate');
具有以下代码:
$timeZone = config('app.timezone'); //change over here
$todayentry = SensorTissue::whereDate('entryDate', Carbon::now($timeZone))
->get()->sortBy('entryDate');