Search code examples
javaandroiddatetimeiso8601

Convert String to Date "2016-01-28T12:08:47.676706-05:00" in android


I am just trying to convert "2016-01-28T12:08:47.676706-05:00" but getting exception. Can anyone suggest me DateFormat like "yyyy-MM-dd HH:mm:ss.SSSZ" to parse the string into Date.


Solution

  • I hope that the code below will help you

    String dateString = "2016-01-28T12:08:47.676706-05:00";
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS", Locale.getDefault());
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date date = format.parse(dateString);