开发者

How to set time zone in PHP

I have a site that has list of stores in different countries ( different time zones ), and it should display when store is OPEN or CLOSED by working hours.

I have javascript that gets DEFAULT timezone GMT offset when daylight saving isn't set, put it inside mysql, and that part works correctly.

My timezone is GMT+1 ( and now i开发者_如何学Pythont's daylight saving active, so it's +1 hour now )

I use php to change zone using this:

date_default_timezone_set('Etc/GMT+1');
echo date('h');

Time here: 10 PM

GMT time: 8 PM

And this code return: 7 PM

So it's like it instead increasing by 1, it decrease, and plus there is no daylight saving...

Can someone tell me what happen here? Is it php bug or something wrong on server?

Thank you...


I'm currently chuckling because I recently had a similar problem. Unfortunately Etc/GMT timezones are deprecated. They break. My personal recommendation? Just use HH:MM or set it by the city (cities don't require daylight savings time adjustments!)


Perhaps date('I') might help in this situation.
Unless there is an option to define a look-up list [GMT offset] - [time zone name]. Then it will be possible to adjust time zone using DateTime\DateTimeZone classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜