How can I find out Zulu timezone in Java DateUtils.parseDate?

I have dates in the format 2008-12-23T00:00:00Z . This is very similar to the ISO 8601 format with the Zulu time zone (UTC). I though the following code would analyze it (using commons-lang ):

 String pattern = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(); Date d = DateUtils.parseDate(dateToParse, new String[] { pattern }); 

If I take the same template ( yyyy-MM-dd'T'HH:mm:ssZZ ), but delete the time zone, it works.

Do you know how I can find out the time zone of Zulu? I only have access to Java 1.4 and Jakarta commons-lang. No Joda Time for me yet ...

+15
java date timezone parsing
Jan 08 '09 at 14:55
source share
2 answers

Looks like a bug in commons-lang FastDateFormat . Tell them about it and you have to fix it in the end. Before that, you could try to pre-process the dates and replace "Z" with "+00"

+4
Jan 08 '09 at 15:06
source share

I think commons-lang uses the built-in DateFormat or SimpleDateFormat that throws a ParseException for your date. If all of your input lines end with a trailing Z, you can use this:

 java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // explicitly set timezone of input if needed df.setTimeZone(java.util.TimeZone.getTimeZone("Zulu")); java.util.Date date = df.parse("2008-12-23T00:00:00Z"); 
+44
Jan 08 '09 at 15:31
source share



All Articles