duanbin4847
2017-06-06 10:48
浏览 91
已采纳

PHP:使用时区获取当前语言环境

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?

图片转代码服务由CSDN问答提供 功能建议

我正在使用时区根据他的时区获取用户的确切时间。 我有一个下拉列表,为用户选择时区,并在选择时区时显示当前时间。 我正在使用的代码是:

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

工作正常。 我希望使用时区来获取该用户的语言环境,就像我获得该时区的当前时间一样。

如何使用时区实现当前区域设置? PHP是否有任何解决方案来使用时区获取当前区域设置?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douduxia1551 2017-06-06 16:22
    已采纳

    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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题