問題描述
Intl.DateTimeFormat 中 dayPeriod 的參考 (Reference for dayPeriod in Intl.DateTimeFormat)
什麼是 JavaScript Intl.DateTimeFormat
中的 dayPeriod
,在 en‑US 語言環境中可以採用哪些值?另外,它在最近的瀏覽器中是否有廣泛的支持?
我似乎找不到任何參考。
參考解法
方法 1:
The only reference I could find was this Unicode Common Locale Data Repository (CLDR) table, and the associated downloads page. I am not sure how browsers implement it.
Fun fact, the number of day periods varies across locales. English has 4 (morning, afternoon, evening, night), while for example German has 6.
An excerpt from the xml file:
<dayPeriodRules locales="root">
<dayPeriodRule type="am" from="00:00" before="12:00"/> <!‑‑ AM ‑‑>
<dayPeriodRule type="pm" from="12:00" before="24:00"/> <!‑‑ PM ‑‑>
</dayPeriodRules>
<dayPeriodRules locales="en">
<dayPeriodRule type="midnight" at="00:00"/> <!‑‑ midnight ‑‑>
<dayPeriodRule type="noon" at="12:00"/> <!‑‑ noon ‑‑>
<dayPeriodRule type="morning1" from="06:00" before="12:00"/> <!‑‑ morning ‑‑>
<dayPeriodRule type="afternoon1" from="12:00" before="18:00"/> <!‑‑ afternoon ‑‑>
<dayPeriodRule type="evening1" from="18:00" before="21:00"/> <!‑‑ evening ‑‑>
<dayPeriodRule type="night1" from="21:00" before="06:00"/> <!‑‑ night ‑‑>
</dayPeriodRules>
(by Christophe、Christophe)