在PHP中获得更长的时区名称 [英] Get longer time zone name in PHP

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

问题描述

考虑到时区缩写,例如 EST,我可以使用 timezone_name_from_abbr 。是否有任何函数返回类似东部标准时间的信息?

Given a time zone abbreviation like "EST", I can get "America/New York" by using timezone_name_from_abbr. Is there any function that returns something like "Eastern Standard Time"?

推荐答案

通常,您不应该信任 timezone_name_from_abbr 函数,因为它仅返回找到的带有匹配缩写的 first 条目。时区缩写不是唯一的。例如,共有5个不同的时区,共享缩写 CST。有关歧义的更多示例,请参见Wikipedia上的此缩写列表

In general, you should not trust the timezone_name_from_abbr function, because it only returns the first entry that it finds with a matching abbreviation. Time zone abbreviations are not unique. For example, there are 5 different time zones that share the abbreviation "CST". See this list of abbreviations on Wikipedia for even more examples of ambiguity.

作为PHP的特殊情况,请考虑缩写 IST。可能会期望 timezone_name_from_abbr( IST)返回表示印度标准时间的亚洲/加尔各答 。但是,它实际上返回亚洲/耶路撒冷 ,代表以色列标准时间。两个时区都使用IST的缩写,但是亚洲/耶路撒冷 的字母顺序是第一个。

As a specific case for PHP, consider the abbreviation "IST". One might expect timezone_name_from_abbr("IST") to return "Asia/Kolkata", representing Indian Standard Time. However, it actually returns "Asia/Jerusalem", representing Israel Standard Time. Both time zones use the IST abbreviation, but "Asia/Jerusalem" comes first alphabetically.

,您现在应该明白为什么仅给定 EST的函数返回 Eastern Standard Time也不可行。尽管EST可能有可能,但并非在所有情况下都有效。还要考虑东部标准时间是英语,并且还有其他缩写和不同语言的文字描述。

With that in mind, you should now see why it would also not be practical for a function to return "Eastern Standard Time" given only "EST". While it might be possible for EST, it won't work in all cases. Also consider that "Eastern Standard Time" is in English, and there are other abbreviations and textual descriptions for different languages.

有一个项目包含您正在谈论的信息(来自Unicode),并称为通用语言环境数据存储库(或CLDR)。使用CLDR数据,您将能够编写接受时区标识符的函数,例如 America / New_York ,以及语言/语言环境代码,例如 en-US ,并返回缩写 ET, EST和 EDT以及名称 Eastern Time, Eastern Standard Time和 Eastern Daylight时间。然后,您需要根据您所谈论的上下文和/或特定时间来决定使用哪个名称和缩写。

There is a project that contains the information you're talking about, which is from Unicode, and called the Common Locale Data Repository (or CLDR). Using CLDR data, you would be able to write functions that that accept a time zone identifier such as "America/New_York", and a language/locale code such as "en-US", and return the abbreviations "ET", "EST" and "EDT", and the names "Eastern Time", "Eastern Standard Time", and "Eastern Daylight Time". You would then need to decide which name and abbreviation to use, based on the context and/or specific time you were talking about.

我已经为.NET,称为 TimeZoneNames 。对于PHP,您将需要类似的东西。我不知道要推荐哪种特定的PHP,但是也许有人写过,或者也许您可以直接使用CLDR源数据来创建所需的功能。

I've written such a library for .NET, called TimeZoneNames. You would need something similar for PHP. I don't know of a particular one to recommend for PHP, but perhaps someone has written one, or perhaps you can create the functions you need by directly consuming the CLDR source data.

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

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