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

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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: