我正在尝试使用GMT值获取时区名称 [英] I'm trying to get timezone name using GMT value

查看:53
本文介绍了我正在尝试使用GMT值获取时区名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库表中创建了unix时间戳.我知道用户的时区也保存在表格中,并且格式为"GMT + 04:00","GMT + 05:30"

I have unix timestamps created in a database table. I know user's timezone it is also saved in a table and int the format of "GMT+04:00" , "GMT+05:30"

我想做的是获取时间戳,并根据用户的时区向他们显示可读的时间.

What I'm trying to do is take the timestamp and show readable time to the users according to their timezone.

例如.

$startTime = '1524391500';

echo date('h:ia', $startTime) . '<br>';
date_default_timezone_set('America/Fortaleza');
echo date('h:ia', $startTime) . '<br>';

这将给我们结果

10:05am
07:05am

问题是date_default_timezone_set在此不接受时区

The problem is date_default_timezone_set doesn't accept the timezone in this

date_default_timezone_set('GMT+05:30');

所以我需要一种将"GMT + 05:30"转换为"America/Fortaleza"的方法

So I need a way to convert "GMT+05:30" to something like "America/Fortaleza"

有人可以帮我吗?

推荐答案

您所要求的是不可能的.时区和时区偏移是两个不同的东西.

What you ask for is not possible. A time zone and a time zone offset are two different things.

考虑一个时区,例如 America/Sao_Paulo .在标准时间期间使用 -03:00 的偏移量,在夏时制期间使用 -02:00 的偏移量.

Consider a single time zone like America/Sao_Paulo. It uses an offset of -03:00 during Standard Time, and an offset of -02:00 during Daylight Saving Time.

现在考虑您提到的 America/Fortaleza 在整个一年中使用 -03:00 .

Now consider that America/Fortaleza you mentioned uses -03:00 over the entire year.

如您所见,对于给定的时区,我可能有多个偏移量,对于给定的偏移量,我可能有多个偏移量.如果您想自己寻找更多示例,可以查看时区列表及其偏移量.

As you can see, for a given time zone I may have more than one offset, and for a given offset I may have more than one time zone. You can review the lists of time zones and their offsets if you want to find more examples for yourself.

其他答案以及时区标签Wiki .

这篇关于我正在尝试使用GMT值获取时区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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