Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy Date Parsing -- X is an illegal pattern character

Tags:

java

date

groovy

I have the following date string: 2011-09-06T22:02:57-04:00. The problem is the timezone, -04:00. The Java7 docs say I can use XXX to magically match this timezone string: http://download.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

The problem is that Groovy does not support the X character, presumably because it's not using JDK7 yet. The z character doesn't work because it isn't GMT-07:00, only -07:00 What is the easiest way to parse this timezone?

-tjw

like image 769
Travis Webb Avatar asked Sep 07 '11 04:09

Travis Webb


2 Answers

The simplest answer I can think of, is just to use 'Z'. The issue here is that -04:00 isn't recognised by the parser. So why not just run a regex prior to trying to convert it, looking for the final : and removing it.

like image 69
nuzz Avatar answered Sep 28 '22 01:09

nuzz


you can use DatatypeConverter.parseDateTime (jaxb support) to parse this date format.

like image 20
jtahlborn Avatar answered Sep 28 '22 01:09

jtahlborn