获取给定位置的时区偏移量 [英] Get timezone offset for a given location

查看:174
本文介绍了获取给定位置的时区偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中是否可以获取给定位置的时区偏移量?例如.当指定位置悉尼/澳大利亚"时,将时区偏移量设置为"+1100".对于该功能,奖励是牢记夏令时(即知道夏令时并根据其调整偏移量).

Is it possible in PHP to get the timezone offset for a given location? E.g. when given the location "Sydney/Australia" to get the timezone offset as "+1100". Bonus would be for this function the keep daylight savings in mind (i.e. it's aware of daylight savings and adjusts the offset according).

推荐答案

要显示本地日期/时间,可以使用以下内容,其中欧洲/柏林"将替换为用户的时区.

To display a local date/time you can use the following, where 'Europe/Berlin' would be replaced with the user's timezone.

$date = new DateTime($value);
$date->setTimezone(new DateTimeZone('Europe/Berlin'));
echo $date->format('Y-m-d H:i:s');

这篇关于获取给定位置的时区偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆