I have to parse this two date
private static final String d1 = "2013-04-02T08:37:56Z";
private static final String d2 = "2013-04-02T10:37:56+02:00";
for the first one I'm using the pattern
"yyyy-MM-dd'T'HH:mm:ss'Z'"
and for the second one I'm using
"yyyy-MM-dd'T'HH:mm:ssXXX"
but I'm always getting
java.text.ParseException: Unparseable date: ....
here my test code:
private static final String d1 = "2013-04-02T08:37:56Z";
private static final String d2 = "2013-04-02T10:37:56+02:00";
private static final String DATE_FORMAT_WITH_TIMEZONE = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final String DATE_FORMAT_WITH_TIMEZONE2 = "yyyy-MM-dd'T'HH:mm:ssXXX";
public static void main(String[] args) {
try {
SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT_WITH_TIMEZONE);
Date d = df.parse(d1);
System.out.println("d1 = " + d);
df = new SimpleDateFormat(DATE_FORMAT_WITH_TIMEZONE2);
df.setTimeZone(TimeZone.getTimeZone("Europe/Rome"));
Date dt = df.parse(d2);
System.out.println("d2 = " + dt);
} catch (ParseException ex) {
ex.printStackTrace();
}
}
What's wrong in my code?
Your DateFormat Definition is wrong:
private static final String DATE_FORMAT_WITH_TIMEZONE = "yyyyMMdd'T'HH:mm:ss'Z'";
private static final String DATE_FORMAT_WITH_TIMEZONE2 = "yyyyMMdd'T'HH:mm:ssXXX";
There are no minus sign in the string
UPDATE:
After you have updated your question, I think the -
sign is not the minus sign. It only look so. Replace this signs. and try again.