0

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?

user3382203
  • 169
  • 1
  • 6
  • 25
Aditya Sharma
  • 43
  • 2
  • 10

1 Answers1

3

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.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575