如何获取当前区域设置的一周的第一天? (PHP / L8N)

时间:2022-05-27 07:28:14

In most locale, the first day of the week is Monday. In the US (and presumably elsewhere), the week starts on Sunday.

在大多数语言环境中,一周的第一天是星期一。在美国(可能是其他地方),本周从周日开始。

How can find out in PHP, for an arbitrary locale, the current setting for the first day of the week (Sunday or Monday)?

对于任意语言环境,如何在PHP中找到一周中第一天(星期日或星期一)的当前设置?

2 个解决方案

#1


From CLDR's supplemental data:

来自CLDR的补充数据:

<firstDay day="mon" territories="001 AD AI AL AM AN AT AX AZ BA BE BG BM BN BY CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP GR HR HU IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ MY NL NO PL PT RE RO RS RU SE SI SK SM TJ TM TR UA UY UZ VA VN XK" />
<firstDay day="fri" territories="BD MV" />
<firstDay day="sat" territories="AE AF BH DJ DZ EG IQ IR JO KW LY MA OM QA SD SY" />
<firstDay day="sun" territories="AG AR AS AU BR BS BT BW BZ CA CN CO DM DO ET GT GU HK HN ID IE IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP NZ PA PE PH PK PR PY SA SG SV TH TN TT TW UM US VE VI WS YE ZA ZW" />
<firstDay day="sun" territories="GB" alt="variant" references="Shorter Oxford Dictionary (5th edition, 2002)" />

(Territory 001 is "World")

(领土001是“世界”)

#2


Run this command in the shell (bash or sh or etc):

在shell中运行此命令(bash或sh或etc):

locale first_weekday

In PHP, call a process to run this command in sh, and get it's output. In Python, I does a thing like this:

在PHP中,调用进程在sh中运行此命令,并获取它的输出。在Python中,我做了这样的事情:

def getLocaleFirstWeekDay():
  return int(os.popen('locale first_weekday').read())-1

#1


From CLDR's supplemental data:

来自CLDR的补充数据:

<firstDay day="mon" territories="001 AD AI AL AM AN AT AX AZ BA BE BG BM BN BY CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP GR HR HU IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ MY NL NO PL PT RE RO RS RU SE SI SK SM TJ TM TR UA UY UZ VA VN XK" />
<firstDay day="fri" territories="BD MV" />
<firstDay day="sat" territories="AE AF BH DJ DZ EG IQ IR JO KW LY MA OM QA SD SY" />
<firstDay day="sun" territories="AG AR AS AU BR BS BT BW BZ CA CN CO DM DO ET GT GU HK HN ID IE IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP NZ PA PE PH PK PR PY SA SG SV TH TN TT TW UM US VE VI WS YE ZA ZW" />
<firstDay day="sun" territories="GB" alt="variant" references="Shorter Oxford Dictionary (5th edition, 2002)" />

(Territory 001 is "World")

(领土001是“世界”)

#2


Run this command in the shell (bash or sh or etc):

在shell中运行此命令(bash或sh或etc):

locale first_weekday

In PHP, call a process to run this command in sh, and get it's output. In Python, I does a thing like this:

在PHP中,调用进程在sh中运行此命令,并获取它的输出。在Python中,我做了这样的事情:

def getLocaleFirstWeekDay():
  return int(os.popen('locale first_weekday').read())-1