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

DIV區塊內文字左右對齊?

DIV區塊內文字左右對齊?

最近常接到一些英文網站建置的專案....為了讓內容文字能夠左右對齊... 所以我用了以下方式 div...

PHP數字轉國字...

PHP數字轉國字...

什麼鬼...客戶系統的需求竟然有一個數字要轉成國字.... 數字轉國字...數字轉國字...就是要把...

分享 (励志短片) 王德顺 《最炫东北人》 完整版 Wang Deshun - Coolest Northeasterner (Inspirational Short Film)

分享 (励志短片) 王德顺 ...

我們都還年輕啊~ 還是可以一直做夢下去的。 只要有夢,我將可以走的更遠。 我是chung 主業做夢,...

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