tribal tribal - 8 months ago 30
MySQL Question

Jersey has written my mysql timestamp as 2011-09-28T21:48:25Z how do I format it in Java?

I have a mysql backend that has a timestamp field that is auto set as currenttimestamp like so (

timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP). After reading the value as Date, Jersey sends out an xml where the timestamp shows as


Please don't make too much of the backstory: I can't change what I get from Jersey. Now my question is this: how do I parse the 2011-09-28T21:48:25Z from xml as a date that Java understands?




DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") ;
df.setTimeZone(TimeZone.getTimeZone("Zulu")) ;
Date dd = df.parse("2011-09-28T21:48:25Z") ;

...then, optionally,

Timestamp ts = new Timestamp(dd.getTime()) ;