[英]Carbon doesn't automatically convert timezone when using `diffForHumans()` on Laravel
[英]Laravel Timezone doesn't convert to the correct timezone in Laravel
我正在嘗試構建一個簡單的 function ,我想從以 UTC 格式存儲的數據庫中獲取 DateTime 並在其本地時區將其顯示給用戶。 我發現了很多可行的解決方案,但時區不正確。
$time = Carbon::createFromFormat('Y-m-d H:i:s', $user->created_at)->settings(['timezone' => 'Australia/Sydney']);
因此,此代碼采用 $user->created_at, "created_at": "2021-12-02T21:18:31.000000Z",它以 UTC 格式創建於 21:18,即悉尼上午 8:18,然而,當我運行代碼時得到了錯誤的時區“2021-12-02T10:27:29.000000Z”,即上午 10:27。
我不確定發生了什么。 任何幫助將不勝感激
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.