Loading...

PHP 時間時區修正

Temperature: 0 °C

ChungChung
author_tools

一般來說...PHP取得的時間,是格林威治的時間:

但如果要將時間調成臺灣的時區,或其他時區的話,必需要做一些修正:

方法一:


$datetime = date ("Y-m-d H:i:s" , mktime(date('H')+8, date('i'), date('s'), date('m'), date('d'), date('Y'))) ;
echo $datetime ;    // 顯示時間
輸出結果: 2001-03-19 / 17:50:34 ( 台灣當地時區 )


最主要修改的,就是H(時)的部份了,只要將後面的+8,修改為你要的時區與格林威治時區的差值,就可以取得正確的時間了。不過時間是以系統所在位置,也就是你的電腦時間。

只是+8之後還是沒有達到要的時間..因此把+8 改為+16...

方法二:

date_default_timezone_set('Asia/Taipei');


只要做一個時區的宣告,就可以不用擔心有沒有哪邊沒改到了。

https://innstory.com/story-PHP_時間時區修正-224
寫程式筆記

Prev
 man’s_talk

Next
PHP數字1000分位逗號分隔函數numberformat 

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

使FCKeditor所上傳的圖檔檔名亂數化

使FCKeditor所上傳的...

編輯"../fckor/or/filemanager/connectors/php/com...

Android Studio 2.3 陽春型計算機

Android Studio...

andrio55 原本這次的學習課題是,與使用者互動之「按一下」事件處理。 我按照工具書上寫的,完成...

Android Studio 2.3 隨機改變背景顏色

Android Studio...

class55 開始學習APP 其實我照著工具書上的方式總是在宣告變數時會產生問題~ 例如工具書上寫...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format