PHP: Get current locale using timezone

最后都变了- 提交于 2019-12-12 04:37:47

问题


I am using timezone to get exact time of a user according to his timezone. I have a drop down list to select timezone for users and showing their current time as they selected their timezone. The code i am using is:

$timezone = 'America/New_York';
date_default_timezone_set($timezone);
echo date('H:i:s A');

It is working fine. I want to get locale of that user using timezone in the same way I am getting current time for that timezone.

How can I achieve the current locale using timezone? Does PHP have any kind of solution to get current locale using timezone?


回答1:


Locale and time zone are orthogonal. You cannot determine one from the other.

  • America/New_York means that the user's local time is aligned to New York City, which happens to be called "Eastern Time" in the United States, which is 5 hours behind UTC during standard time and 4 hours behind UTC when daylight saving time is in effect.

  • en-US (or en_US) means that the user speaks English, with cultural dialects (word choice, numbers, dates, etc.) of the United States. For example, en-US uses MM/DD/YYYY date format, and en-GB uses DD/MM/YYYY date format, but we both call our first month "January", while es-MX calls their first month "enero".

I could very well be an English speaking American visiting Japan, thus my time zone would be Asia/Tokyo even though my local would still be en-US.

Aside: A hyphen (-) is the correct character to split language and country codes in a locale identifier. Though some implementations have substituted an underscore (_), this is not correct by the IETF language tag specification.



来源:https://stackoverflow.com/questions/44387956/php-get-current-locale-using-timezone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!