-1

how to convert this string "2016-10-08T01:00:00-07:00" to date object in Java? I want to know what is string format to use with SimpleDateFormat.

I have try

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

try {
  Date date = format.parse("2016-10-08T01:00:00-07:00");
} catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

}
shmosel
  • 49,289
  • 6
  • 73
  • 138
Sophon Men
  • 179
  • 1
  • 2
  • 10

3 Answers3

3

Change your format from Z to X will work . Detail is here

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
Viet
  • 3,349
  • 1
  • 16
  • 35
0

Date date = format.parse("2016-10-08T01:00:00-07:00");

should be

Date date = format.parse("2016-10-08T01:00:00-0700");

The time zone should not have a colon delimiting hours and minutes.

Tigin
  • 99
  • 7
0

You can try SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");

Best solution to refer @ Change date format in a Java string

Community
  • 1
  • 1
BNayak
  • 26
  • 5