PHP:使用时区获取当前语言环境 [英] PHP: Get current locale using timezone

查看:99
本文介绍了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.

如何使用时区实现当前语言环境? PHP是否有任何解决方案可使用时区获取当前语言环境?

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

推荐答案

区域设置和时区是正交的.您无法彼此确定.

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

  • America/New_York表示用户的本地时间与纽约市对齐,在美国恰好称为东部时间",该时间在标准时间比UTC落后5小时,比UTC落后4小时夏令时生效.

  • 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(或en_US)表示用户说英语,并使用美国的文化方言(单词选择,数字,日期等).例如,en-US使用MM/DD/YYYY日期格式,而en-GB使用DD/MM/YYYY日期格式,但是我们都将第一个月称为一月",而es-MX则将其第一个月称为"enero". .

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".

我很可能是访问日本的说英语的美国人,因此即使我的当地时间仍然是en-US,我的时区也将是Asia/Tokyo.

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.

在旁边:连字符(-)是在区域标识符中分割语言和国家/地区代码的正确字符.尽管某些实现已替换了下划线(_),但 IETF语言标记规范中的这不正确" .

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.

这篇关于PHP:使用时区获取当前语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆