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

圖型插件Elastislide

圖型插件Elastislid...

teach Elastislide是一款好用的圖形插件......

Photoshop 曲線文字建置

Photoshop 曲線文字...

Photoshop一直都是很強悍的繪圖軟體。 裡頭的【鋼筆工具】,可以拉貝茲曲線的.... 我剛開始...

網站植入Facebook登入FB.api請求修改

網站植入Facebook登入...

會特別紀錄下來的原因是因為FB.api請求又調整了~ function fblogin() {//開...

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