• Post Reply Bookmark Topic Watch Topic
  • New Topic

timezone conversion using jodatime  RSS feed

 
sony rao
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

iam trying to convert datetime in one timezone to corresponding datetime in
other timezone. iam using jdk 1.5 and jodatime 1.5.1

Iam trying to convert March 30th 2008 2am in Europe/Moscow to equivalent datetime in india.

Europe/Moscow undergoes DST on March 30th 2008 at 2am.
So When i feed this time, iam getting this exception

"Exception in thread "main" java.lang.IllegalArgumentException: Illegal instant due to time zone offset transition: 2008-03-29T23:00:00.000" ...

if i give any datetime other than this, conversion is fine.

here goes my code...

DateTimeZone fromZone = DateTimeZone.forID("Europe/Moscow"); DateTimeZone toZone = DateTimeZone.forID("Asia/Calcutta");
//yyyy mm dd hh mm ss ms
DateTime dt = new DateTime(2008, 03, 30, 02, 0, 0, 0, fromZone);
System.out.println(dt.toDateTime(toZone));


Please help me in finding a solution.
Thanks in advance.
[ March 11, 2008: Message edited by: sony rao ]
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure. DateTimeZone appears not to be a class in the standard API; it appears to be programmed to throw that Exception if a nonexistent time is passed to its constructor.
There is no such thing as 2.00 on 30th March; it passes directly from 1:59:59.999 to 3:0:0 rather like "Go to Jail" in Monopoly; it doesn't pass "go" nor does it pass 2.00 o'clock.

You will have to find the API documentation for that class and see what it says; I think you are stuck with it.

BTW: What happens if you pass 1:30:0 on 26th October 2008, when summer time ends? There are two 1:30s that day!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!