0

I am trying to convert this date 2013-03-04T12:08:52.74+08:00

formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date date = formatter.parse(dateresult);

But it ends with an exception

03-07 19:17:05.493: W/System.err(2006): java.text.ParseException: Unparseable date: "2013-03-04T12:08:52.74+08:00" (at offset 19)

I tried this. But same exception occured. Does anyone know of another (possibly better) way to accomplish this ?

4
  • 4
    i think you have millisecond part in your string .74 but have not mentioned it in your format string Commented Mar 7, 2013 at 13:58
  • 1
    This is the ISO 8601 format. This SO question may helps you: stackoverflow.com/questions/2201925/… Commented Mar 7, 2013 at 14:02
  • @Abu oh.. I mssd it.. bt it doesn't make any progress. And now I've used Joda-Time and worked. Thanx for ur reply :) Commented Mar 8, 2013 at 5:49
  • @MiguelPrz thanx bro.. that link help me lot :) Commented Mar 8, 2013 at 5:50

4 Answers 4

1

You can use joda-time. It supports ISO8601 standard.

joda-time manual

Sample:

DateTime dt = new DateTime("2013-03-04T12:08:52.74+08:00");
System.out.println(dt.toString());
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
System.out.println(
        fmt.parseDateTime("2013-03-04T12:08:52.74+08:00"));
Sign up to request clarification or add additional context in comments.

Comments

0

Use:

formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");

To include milliseconds (.74)

Comments

0

In addition to you missing the milliseconds as baraky pointed out, you'll also run into the ISO-8601 time zone issue when parsing dates with Java. It was addressed in this question.

Comments

0

Also, in addition to @baraky's answer, your input date's time zone format does not conform to your format string's specification. Your format string has 'Z' (the literal letter Z). It seems that your input string has the format X. So you might want to use:

formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSX");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.