tags:

views:

260

answers:

1

I need to convert from the Unix TZ variable of the form: stdoffset[dst[offset][,start[/time],end[/time]]] into a Java TimeZone object. For example, convert AEST-10AEDT-11,M10.1.0/02:00:00,M4.1.0/03:00:00 into a Java TimeZone object that represents "Australia\Sydney". Before I go and write the code myself I'd like to know I'm not inventing the wheel again, so does anyone know if there's a library already available that can do this?

Cheers, Matt

+1  A: 

It will be really hard to write such a conversion program. On Unix, you can have customized daylight rules and Java provides no such facility. It's possible to search through tzfile trying to find a match but you have to convert the TZ rule into the format used by tzfile, an enormous task.

Why don't you use the same zone id used in Java? For example, you can set TZ as,

export TZ=Australia/Sydney

This is supported on most modern Unix systems (like Linux, Mac OS X). Search /etc/zoneinfo or /usr/share/zoneinfo. If you can find a file for your timezone, the ID will work.

I also started on a custom TimeZone to handle the old TZ format but I was able to convince the sysadmin to use the zone id so I didn't finish it. The difficult part is to implement the useDaylightTime() because the rules used in TZ is very complicated.

ZZ Coder
Thanks for the feedback, I thought as much.
Matt