Question

I have been looking for hours to find a way to display list of timezone that should look exactly like this:

enter image description here

I found ways to display a list of abbreviations, a list with gmt, but how do i get names like Central European Time

I can only find lists with names like: Europe/amsterdam, Europe/berlin etc. And that's exactly what i'd not need.

Indeed i know i can make a custom select, but yet i'd prefer to create such a list with php instead.

Était-ce utile?

La solution

The example list you've shown looks like it was derived from the data provided by the U.S. Naval Observatory's Time Service Dept.. They have since updated names like "USSR Zone 3" to be called "Russian Federation zone three". But these are just some administrator's own personal interpretations of what they think time zones should be named. They aren't official by any means.

If you search the web, you'll find plenty of other static web sites (like here and here) that seem to think these are somehow official and set in stone. That's just not the case. I mean, if you live in Russia do you think you would ever really say that you follow "Time Zone 3"? No, you would probably say that you follow "Moscow Time", or perhaps "Moscow Standard Time". (See Wikipedia's entry on Time in Russia.)

So that's just one example, but the question then of where to get the time zone names from? The general problem is that they are not in the TZDB data, so PHP doesn't give them back to you. As I've illustrated, they are subject to interpretation. Time zone abbreviations are also subject to interpretation. If you want a slightly better interpretation, the one provided by here appears to be more plausible. But it will probably still need to be filtered for your purposes.

A better source of time zone names comes from the Unicode CLDR. They offer a very large data set that translates many things into different languages, and one of the things they cover are the names of the time zones. But to get a time zone name from an IANA time zone key out of the CLDR data, you have to jump through a lot of hoops:

  • Look up the key in the CLDR MetaZones list.

    CLDR Metazone Mapping Data

  • Find the Language File that you are interested in, English for example.

  • Find the metazone in the language file, and determine which form of that name you want.

    CLDR Translation Data

Of course, you would have to do all of that programmatically from their XML or JSON data sources. And you'd have to do it for each time zone you were interested in.

Why go to all that trouble? Well if you have a user who speaks another language, for example French, then would you want to show them "Central European Standard Time" or "heure normale de l’Europe centrale"? Only the CLDR can give you that sort of translation.

So I know this didn't directly give you PHP code that you can use right away, but hopefully now you understand why this isn't directly possible, and that just about any list you come upon is subject to someone's own personal interpretation and is likely to be outdated or partially incorrect.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top