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

jQuery效果滑動隱藏

jQuery效果滑動隱藏

因為需要所以紀錄下來,主要是要透過點選按鈕將字串隱藏或顯示出來... 雖說可以直接用hide或是sh...

Google map 功能導入

Google map 功能導...

blogmap 寫故事還是得有地圖才好厚! 前幾天,sam同我說有一個客戶有Google map的需...

關掉phpinfo()

關掉phpinfo()

pexelsphotod 配置php環境的時候往往都會寫 phpinfo(); 這個函數來測試php...

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