How to get timezone id of a city

I have a city name or actually it is three letters city code such as NYC, BKK, HKG. I need to convert local time of a city to UTC time, so that I use calendar class and timezone id of that city right?

I don't know how to find the timezone id of a city. Does anyone know it? Thanks in advance

[306 byte] By [ouna] at [2007-10-2 2:00:54]
# 1
HI,I doubt that it's possible to get the timezone from a city id. Btw. Aren't there more cities than combinations?Kaj
kajbja at 2007-7-15 19:42:08 > top of Java-index,Java Essentials,Java Programming...
# 2
1. Build up a map from city name to timezone. Note: you'll have to work out how to handle cities which have the same name.2. Query the map.
YAT_Archivista at 2007-7-15 19:42:08 > top of Java-index,Java Essentials,Java Programming...
# 3

You can get all the all the available TimeZone IDs supported:

final String[] timezoneIDs = TimeZone.getAvailableIDs();

for (int i = 0; i < timezoneIDs.length; i++) System.out.println(timezoneIDs[i]);

I.e:

America/New_York

Asia/Bangkok

Asia/Hong_Kong

YoGeea at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 4
A 3 letter combination would allow 17576 unique entries, I have no idea if there are more cities than that in the world, the system works for international airports, and most cities have at least one, so I would assume there are fewer cities than that.
macrules2a at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 5

> A 3 letter combination would allow 17576 unique

> entries, I have no idea if there are more cities than

> that in the world, the system works for international

> airports, and most cities have at least one, so I

> would assume there are fewer cities than that.

Do you say that most cities have an international airport? Hmm.. Sweden has less than 10 international airports, but we have more cities than that. There are also city names which exists in more than one country e.g. Stockholm (Sweden and USA)

Kaj

kajbja at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 6

> A 3 letter combination would allow 17576 unique

> entries, I have no idea if there are more cities than

> that in the world, the system works for international

> airports, and most cities have at least one, so I

> would assume there are fewer cities than that.

Well, ICAO uses four letters now. Every three-letter IATA airport designation e.g. in the US was prefixed with a 'K'.

CeciNEstPasUnProgrammeura at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 7
> Well, ICAO uses four letters now. Every three-letter> IATA airport designation e.g. in the US was prefixed> with a 'K'.When did they do that? :-( all those cool ones like LAX are now KLAX?
macrules2a at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 8

> When did they do that? :-( all those cool ones like

> LAX are now KLAX?

I don't know, but must have been a while ago already. KLAX and KATL and KJFC. But I guess since the non-flying folks never get into touch with ICAO codes, nobody noticed. Travelling agencies and suitcase tags stick with the IATA designations.

CeciNEstPasUnProgrammeura at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 9
Thank you all, I still doubt that TimeZone.getAvailableIDs() will have all the cities that have an international airport since I need only those cities. I've worked in an airline company and they still use three letter code to represent an airport. :D
ouna at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...
# 10
This has got to be on the net somewhere.
paulcwa at 2007-7-15 19:42:09 > top of Java-index,Java Essentials,Java Programming...