Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java SimpleDateFormat - Correct format for Postgres "timestamp with timezone" date format

I'm querying a Postgres database and looking for the best way to store a Postgres "timestamp with timezone" information.

the format is "yyyy-MM-dd' 'HH:mm:ss.SSSzz" (i.e. "2014-04-22 05:39:49.916+03")

i'd like to use a timestamp oriented type/class to keep the info (not String)

the following throws Unparsable date for all the TIME_FORMATS i could think of:

final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSz";
final SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT);
final java.util.Date utilDate = sdf.parse("2014-04-22 05:39:49.916+03");
like image 888
Joey Baruch Avatar asked Aug 25 '15 10:08

Joey Baruch


1 Answers

Your format is having ISO Timezone, so use X (not z).

final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSX";

More Info here

like image 144
Codebender Avatar answered Nov 03 '22 00:11

Codebender