[英]Laravel Eloquent doesn't display date/time as in database timezone
我試圖獲得與 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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.