PHP 使用 IntlDateFormatter 进行日期格式化

PHP Date Formatting with IntlDateFormatter

我注意到,当使用 PHP 的 IntlDateFormatter 格式化日期时,结果可能因语言而异。示例:

$formatter = new IntlDateFormatter("en_GB",
                        IntlDateFormatter::SHORT, IntlDateFormatter::NONE,
                        "Europe/Vienna");

$date = $formatter->format(0);

在此示例中,$date 将是 31/12/1969,但如果我使用 de_DE 作为区域设置,$date 将是 31.12.69。使用 IntlDateFormatter::MEDIUM:

时差异更大

有没有办法在不指定格式的情况下获得更多相似的结果?

正如ICU docs所说:

  1. SHORT is numeric, such as 12/13/52 or 3:30pm
  2. MEDIUM is longer, such as Jan. 12, 1952
  3. LONG is longer, such as January 12, 1952 or 3:30:32pm
  4. FULL is completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST

所以您可能是对的,例如:"who defines those short/medium formats, and who decide about how it looks like?".

所有类似的决定都得到了 CLDR 的确认,他们的过程 is described as:

Once data for a country and language has been received, the data from the different sources will be compared to show agreements and differences. Initial data contributions are normally marked as draft; this may be changed once the data is vetted.

Note that there are two types of data in the repository:

  • Common Data: The contents is decided upon by the CLDR Technical Committee, following its procedures and this process.
  • Comparison data: The contributor can be an individual or an organization. Data is normally gathered by calling public APIs, to ensure that the data matches what is actually in use. The data is only for comparison, and will not be changed except where necessary to update the data to match the external source. The only requirement is that all changed data be versioned, and the Version Numbering Scheme be used.

Contributors are encouraged to use local language and country contacts, inside and outside their organization, to help vet current common data and any new proposals for addition or amendment of common data. In particular, national standards organizations are encouraged to be involved in the data vetting process.

可能,并非总是(在世界各地)中等格式看起来像:12, Jan 2015,并在国家层面做出决定。如果您作为德国人对此有顾虑 - 您可以尝试 fill a ticket with change proposal.