我有一個代碼可以獲取訂單的日期和時間。我在 Laravel PHP 中這樣做。我知道如何使用 date() 在 PHP 中回顯日期。
然而,這里的挑戰是轉換時區。下面的代碼可以正常作業并正確輸出日期,但它添加了一個前綴1,因此我的日期現在看起來類似于
1 February 19, 2022 05:14 am
代碼是:
{date_default_timezone_set('Africa/Nairobi')} {$order_order_datetime|get_datetime:1}
挑戰在于取消前綴。我無法知道它的1來源。
uj5u.com熱心網友回復:
配置/app.php
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
你可以在 Laravel 的這個組態檔中更改你的時區。

但是,如果您使用的是簡單的 PHP,您應該遵循:here
您可以將此代碼寫入您的 index.php 或條目 php 檔案。您不需要回顯date_default_timezone_set 此功能。它說它更改了時區并回傳 1。這就是您看到 1 的原因。您正在回顯函式的結果。您不需要回顯該結果。只需要跑。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/428448.html
