Changing timezone without changing time in Java

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-05-20T11:14:47Z Indexed on 2010/05/20 11:20 UTC
Read the original article Hit count: 315

Filed under:
|
|
|

Hi! I'm receiving a datetime from a SOAP webservice without timzone information. Hence, the Axis deserializer assumes UTC. However, the datetime really is in Sydney time. I've solved the problem by substracting the timezone offset:

Calendar trade_date = trade.getTradeDateTime();
TimeZone est_tz = TimeZone.getTimeZone("Australia/Sydney");
long millis = trade_date.getTimeInMillis() - est_tz.getRawOffset();
trade_date.setTimeZone( est_tz );
trade_date.setTimeInMillis( millis );

However, I'm not sure if this solution also takes daylight saving into account. I think it should, because all operations are on UTC time. Any experiences with manipulating time in Java? Better ideas on how to solve this problem?

© Stack Overflow or respective owner

Related posts about java

Related posts about timezone