I have a country e.g. "Canada" and I know its offset i.e. GMT-8:00.
My questions are:
1. How can I get the current date in Canada using Java TimeZone or any other method?
2. How can I know whether at this moment (at current datetime) daylight saving behaviour is being observed in Canada or not. (Basically if I get Country to Daylight Saving Rules mapping using a java method, that will solve this problem.)
Is there any example for reference?
Thanks a lot for your help.
1.) Get the TimeZone instance from the time zone identifier. If you need a list of time zone identifiers use TimeZone.getAvailableIDs().
2.) To simply print a date in the selected TimeZone, create a SimpleDateFormat in the format you want and call its setTimeZone() with the TimeZone discovered above. Then call format() for a String representation of the date.
3.) Call inDaylightTime(new Date()) on the TimeZone instance obtained earlier to return if it is now DST in the time zone.
I wouldn't bet that Java implements the more obscure time zones but you should be able to pick a TZ from that.
Just for grins, from the Wikipedia article on US time zones:
"Arizona and Hawaii use standard time throughout the year. However:
The Navajo Nation observes DST throughout its entire territory, including the portion that lies in Arizona. But the Hopi Nation, which is entirely surrounded by the Navajo Nation, does not observe DST."
... and your code is not truly internationalized until it supports that! <g>
The main issue is making sure the default time zone has been set correctly on the computer - which is really a job for the person setting setting up the computer. If someone buys a new computer at Fry's in Phoenix and then takes it to Shiprock, chances are they'll need to change the time/date settings in the operating system. And quite possibly the OS won't distinguish between America/Shiprock and America/Denver, so they'll just have to settle for Denver. Which is identical in all but name.