对于strftime还是仅PHP不推荐使用“美国/东部”,“美国/中央”和“美国/太平洋”? [英] Are 'US/Eastern' and 'US/Central' and 'US/Pacific' deprecated for strftime or just PHP?

查看:252
本文介绍了对于strftime还是仅PHP不推荐使用“美国/东部”,“美国/中央”和“美国/太平洋”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个shell脚本(准确地说是zsh),

I have a shell script (zsh, to be precise) which uses

strftime%I:%M%p%Z( %a,%b%d) $ EPOCHSECONDS

生成当前时间,例如

CST 02:45 PM(3月1日,星期四)

"02:45 PM CST (Thu, Mar 01)"

这需要能够显示几个不同美国的时间时区,因此我一直在使用美国/东部,美国/中央和美国/太平洋,例如:

This needs to be able to display the time in several different USA timezones, and so I have been using 'US/Eastern', 'US/Central', and 'US/Pacific' like so:

export TZ='US/Eastern'
strftime "%I:%M %p %Z (%a, %b %d)" "$EPOCHSECONDS"

这似乎很好,我更喜欢使用TZ ='America / CityName',因为它不需要我知道哪个城市是哪个TZ,我只需要告诉它我想要哪个TZ。

That seems to work just fine, and I prefer it to using TZ='America/CityName' because it doesn't require me to know which city is in which TZ, I just need to tell it which TZ I want.

但是,我偶然遇到了 http://www.php.net/manual/en/timezones.others.php 并看到上面写着

However, I happened across http://www.php.net/manual/en/timezones.others.php and saw that it says


请不要使用任何在此处列出的e个时区(除UTC之外),
仅出于向后兼容的原因而存在。

Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons.

我不知道什么问题与美国/地区名称有关,但我很好奇,想知道在可预见的将来使用它们是否可能会引起问题,还是仍然可以安全使用?仅仅是不喜欢它们的PHP,还是每个人都远离它们?

I don't know what the issues are with the US/Region names, but I'm curious to know if using them is likely to cause a problem in the foreseeable future, or are they still safe to use? Is it just PHP which doesn't like them, or is everyone moving away from them?

推荐答案

命名时区的标准格式Olson数据库中的大陆/城市。您提到的旧名称(例如US / Eastern,US / Central等)在tzdata源分发中(作为文件的 backward)作为向后兼容性链接列出。根据文件顶部的注释,这些名称在1993年末可能已成为向后兼容的链接。

The standard format for naming timezones in the Olson database is Continent/City. The "old" names you mention like US/Eastern, US/Central, and many more, are listed as backward compatibility links in the tzdata source distribution (in the file "backward"). According to the comment at the top of the file, these names may have become backward compatibility links in late 1993.

我想我记得我读过这个标准,因为人们认为它更稳定:地缘政治(国家)边界发生变化,城市再也不会四处走动。也许还因为诸如东部和中央之类的名称被认为更加混乱,因为它们在世界不同地区代表不同的时区。但是,目前我找不到任何有关命名原理的参考,因此请不要在此引用。

I think I remember reading that this standard was adopted because it was felt to be more stable: geopolitical (country) boundaries change, cities never move around. Maybe also because names like "Eastern" and "Central" are thought to be more confusing because they mean different timezones in different parts of the world. However, I cannot find any references to the naming rationale at the moment, so don't quote me on this.

首选大陆/城市风格的名称。请注意,像Debian和Ubuntu这样的操作系统会要求您使用这些名称选择系统时区(除非它们在安装时自动检测到该时区)。使用这些名称实际上并不需要,正如您所说的,知道哪个城市在哪个TZ,因为城市名称是时区名称的一部分!因此,如果您刚好学会了除国家/地区名称之外的其他大陆/城市名称,那么您已经可以了。

The Continent/City-style names are preferred. Notice that operating systems like Debian and Ubuntu ask you to select the system timezone using these names (unless they autodetect it at installation time), Using these names you wouldn't really be required to, as you say, "know which city is in which TZ" because the city name is, well, part of the timezone name! So if you happen to have learned the Continent/City names instead of or in addition to the Country/Region names, you're already OK.

话虽如此,我不要以为这些名字会消失。在时区邮件列表中,尽管PHP提出了建议,但它们绝对总是被称为向后兼容性,而不是不推荐使用,并且它们打算保留下来。

That being said, I do not think that these names will ever disappear. On the timezone mailing list, they are definitely always called "backward compatibility", not "deprecated", and are intended to stay, notwithstanding what PHP recommends.

这篇关于对于strftime还是仅PHP不推荐使用“美国/东部”,“美国/中央”和“美国/太平洋”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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