2017-09-25 140 views
0

我想在下拉菜單中顯示加拿大和美國的時區。 經過一番搜索,我嘗試申請DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'US')這很酷,但它只返回美國時區,而不是加拿大也試圖使用DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'US'|'CA')它只返回太平洋/阿皮亞。 而DateTimeZone::listIdentifiers(DateTimeZone::AMERICA)返回來自所有美洲的時區。加拿大和美國時區PHP

+0

自己計算加拿大的時區,使用美國時區。 – jack

+3

'listIdentifiers(PER_COUNTRY)'一次只返回一個國家,所以調用它兩次併合並結果:'array_merge(DateTimeZone :: listIdentifiers(DateTimeZone :: PER_COUNTRY,'US'),DateTimeZone :: listIdentifiers(DateTimeZone :: PER_COUNTRY,'CA'));' –

+3

'|'只適用於二進制掩碼。如果你使用二進制或字符串'US'和'CA',你會得到新的字符串'WS',它是[Samoa](https://en.wikipedia.org/wiki/Samoa)(其首都是阿皮亞)。 – deceze

回答

0

溶液在COMENT提供上述

'items' => array_merge(DateTimeZone::listIdentifiers(DateTimeZone::PER_‌​COUNTRY, 'US'), DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'CA')) 
相關問題