How to convert PostgreSQL timestamp with time zone to DateTime?

java, jodatime, postgresql, timestamp

Solution

Here a genuine Joda answer. Have you tried following pattern in `org.joda.time.format.DateTimeFormat`?

"yyyy-MM-dd HH:mm:ssZ"

I see that your time zone offset is only specified in hours, not minutes. So maybe you need simple preprocessing and double Z like this:

String psqlDate = "2013-11-17 14:08:33+01";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZZ");
DateTime dt = DateTime.parse(psqlDate + ":00", formatter);

Problem

This is a date which I get in my application: ``` String psqlDate = "2013-11-17 14:08:33+01"; ``` What is best way to convert `psqlDate` to joda `DateTime`? [EDIT] I can use `DateTime` parse method. It works fine with timestamp whitch have splitted information about date and time with T - `2013-11-17T14:08:33+01`. This should work with good pattern: ``` DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd..."); DateTime dt = DateTime.parse((String) obj, formatter); ``` What is correct pattern to PostgreSQL timestamp with time zone?

Original source