Friday 19 September 2008

Convert java Date time between timezones.

The standard way to specify your target timezone is GMT +/- hours minutes
e.g. for BST i can say "GMT+1"

String mytimeZone = "GMT+1";
GregorianCalendar abroad = new GregorianCalendar(TimeZone.getTimeZone(mytimeZone));
System.out.println(abroad.getTime());

//Format the timezone specific date display..
DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
df1.setTimeZone(TimeZone.getTimeZone(mytimeZone));
System.out.println(df1.format(abroad.getTime()));

//Format to GMT time
df1.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(df1.format(abroad.getTime()));

1 comments:

Anonymous said...

I κnoω this if off tοpic but Ӏ'm looking into starting my own blog and was curious what all is needed to get set up? I'm aѕsuming having a blog liκe уouгs ωould
cost a pretty ρenny? I'm not very web smart so I'm not 100% certain. Any recommendations or advice would be greatly appreciated. Thank you

Here is my web page - boppelans.info
my web site: http://helenparkhurst.nl/