Convert Timezone Using Joda Time
Posted by tech on
July 6, 2009
Joda Time provides a quality replacement for the Java date and time classes. The design allows for multiple calendar systems, while still providing a simple API. Converting a Joda DateTime object from one timezone to another is pretty easy and saves you quite a number of lines of code. See method below.
public static Date convertJodaTimezone(LocalDateTime date, String srcTz, String destTz) { DateTime srcDateTime = date.toDateTime(DateTimeZone.forID(srcTz)); DateTime dstDateTime = srcDateTime.withZone(DateTimeZone.forID(destTz)); return dstDateTime.toLocalDateTime().toDateTime().toDate(); }
Since Joda Time has its own class for storing Date and Calendar objects, the DateTime class has its own toDate() method for converting it to a java.util.Date.
Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.





