簡體   English   中英

Laravel Eloquent 不像數據庫時區那樣顯示日期/時間

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM