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

解決手機瀏覽器上點擊輸入框放大問題

解決手機瀏覽器上點擊輸入框放...

開發RWD的網站已經是趨勢,主要也是因為手機用戶實在是太多 但在過程中一直有個問題困擾著我.... ...

黑客松Hackathon

黑客松Hackathon

這個星期六日要同朋友去參加一個聚會...黑客松Hackathon... 老實說我根本不知道那是什麼....

Mysql最怕就是手賤

Mysql最怕就是手賤

今天我手賤了眼盲了@@... 錯把delete當成UPDATE....啃!!今天下午超不順的... ...

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