I am working on a web application, where info about various cities is displayed. In this application, I need to display the current time of "that" city on whose page the user is. For example, if the user in on the London page, then the current time of London must be displayed. How can I do this cause my locales, and date time concepts are not so sound. Please help!
I'd start by looking at the Calendar (especially GregorianCalendar), DateFormat (especially SimpleDateFormat to start with) and Date APIs in the JDK. I'd suggest simply trying a few things out and then posting back here with specific questions.
A Locale does not affect timezone. Take Canada for example; two common Locales are en_CA and fr_CA. This merely tells me the language and formatting of numbers and such. It doesn't tell me where in Canada, and thus the timezone, the user is. In fact, it doesn't even tell me the user actually is in Canada; just that they want things formatted using the language and formatting rules of that locale. If I traveled to Italy, I'd still keep my laptop's locale as en_US so I would get English messages formatted with typical US conventions (since I don't speak Italian and am use to seeing 1 million as 1,000,000.00 and not 1.000.000,00) But I'd likely change my computer's timezone so things would be in local time.
Depending on you application, and its usage pattern, you can also have a registration page. In that page, you ask the user for their timezone and then save it, either in a cookie (less desirable since people delete them often these days) or in a server side user database. Of course the latter only works for an authenticated site where you know who the user is.
I hope that helps. [ September 01, 2008: Message edited by: Mark Vedder ]