要偏移的 PHP 时区名称 [英] PHP Timezone Name to Offset

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

问题描述

我将如何将时区名称(亚洲/迪拜"、欧洲/安道尔"等)转换为几小时(甚至几秒,因为我可以从那里转换)的 GMT 偏移量.

How would I go about converting a timezone name ("Asia/Dubai", "Europe/Andorra", etc) to a GMT offset in hours (or even seconds, since I can convert it from there).

大多数人要求相反,但我需要从 GeoNames 提供的时区名称中获取时区偏移量.

Most people ask for the reverse, but I need to get a timezone offset from the timezone name provided by GeoNames.

推荐答案

你可以使用下面的

<?php

$timezone = 'Pacific/Nauru';
$time = new \DateTime('now', new DateTimeZone($timezone));
$timezoneOffset = $time->format('P');
?>

这篇关于要偏移的 PHP 时区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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