user3111525
user3111525

Reputation: 5203

How do you parse this date format in java?

Simple question: what format should I use with this date?

2011-10-09T05:06:03.000000Z

This one does not work:

"yyyy-MM-dd'T'HH:mm:ssZZ"

From the manual: "The timestamp is calculated from epoch_ticks (zulu), format=%Y-%m-%dT%H:%M:%S.%fZ"

Upvotes: 0

Views: 315

Answers (1)

Dan Bliss
Dan Bliss

Reputation: 1744

I think the short answer is "you can't". For some reason Java does not support "Z" as a time zone identifier. You can do a workaround like this though:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = df.parse("2011-10-09T05:06:03.000000Z");

This assumes that the date will be in UTC and ignores the Z.

Upvotes: 1

Related Questions