1

I have a String in this format : 2016-08-08T10:27:06.282858+00:00.

I want to parse this string to get the Date object. I tried

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

But I'm getting the error: Unparseable date: "2016-08-08T11:06:22+00:00" (at offset 19)

I tried every other format in place of 'Z' as 'X', 'XXX' but nothing seems to work.

Ran94
  • 139
  • 11

3 Answers3

0

Correct format is "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX". ' ' is used to escape simbols and avoid parsing them.

Maksim Maksimov
  • 115
  • 1
  • 10
0

the 'Z' at the end of your pattern seems to be the problem. I removed it and parsing worked:

@Test
public void testParsing() throws Exception {
    String text = "2016-08-08T10:27:06.282858+00:00";
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS");

    Date date = df.parse(text);
    System.out.println(date);
}

Output:

Mon Aug 08 10:31:48 CEST 2016
Markus Mitterauer
  • 1,560
  • 1
  • 14
  • 28
0

@Ran94 You're trying to parse a wrong date i.e 2016-08-08T11:06:22+00:00 and seems invalid, the correct possible value for this should be 2016-08-08T11:06:22+0000 which can be represented by this format yyyy-MM-dd'T'HH:mm:ssZ. Hope this helps

Nitin Misra
  • 4,472
  • 3
  • 34
  • 52