在處理輸入日期和/或修改日期的日期/時間時,最好使用正常的VARCHAR
,長度大約爲200(或任何其他適合整個日期的值)以存儲完整日期並在您的PHP腳本中處理您的日期/時間。這使您能夠靈活地根據您的PHP代碼中定義的時區來查看您的時間。 Click here查看PHP中的可用時區。
您還可以通過簡單使用PHP的date_format
,以任何可能的格式格式化日期/時間。
我在下面給出了一個參考碼。
//This is the way you define your timezone in PHP code
date_default_timezone_set('Asia/Beirut');
//You can capture the date/time by using the below code. This will store "2017-05-28 23:55:34"
$date_time_registered = date('Y-m-d H:i:s');
//Retrieve the date/time and re-format it as you require. Below code will output "May", full month.
$retrieve_month_only = date_create($row['your_store_date_time']);
$retrieve_month_formatted = date_format($retrieve_month_only, 'F');
echo $retrieve_month_formatted;
你可以參考this link,瞭解PHP日期/時間格式。
是的,我沒有讀過關於默認情況下utc中設置時區的mysql設置時區,但總是在檢索時轉換它。我的php時區設置爲UTC,mysql設置爲我的系統時區。我不想將UTC設置爲mysql的全球時區,因爲它也會影響系統中的其他數據庫。 – kks21199