0

dateString: 2016-08-29T11:39:52.2133065

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    try {
      Date date = dateFormat.parse(dateString);
      return dateFormat.format(date);
    } catch (ParseException e) {
       Log.e(TAG, "Unable to parse date " + e);
    }

The string needs to be converted into 2016-08-29 11:39 but I am getting parse exception.

Coder
  • 3,090
  • 8
  • 49
  • 85
  • This can be solve your problem http://stackoverflow.com/a/19112487/5291413 – Berkay92 Aug 29 '16 at 14:57
  • Possible duplicate of [Java SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") gives timezone as IST](http://stackoverflow.com/questions/19112357/java-simpledateformatyyyy-mm-ddthhmmssz-gives-timezone-as-ist) – Shark Aug 29 '16 at 15:08

2 Answers2

1

The format passed to the date formatter should correspond to the format of the string to be parsed. In the case of "2016-08-29T11:39:52.2133065" the date formatter should be:

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

You will also need a new formatter where you specify the output format:

SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

Use them like this:

Date date = dateFormat.parse(dateString);
return newFormat.format(date);
Mikael
  • 188
  • 1
  • 3
0

Try this,remove T in your dateString,

                String dateString ="2016-08-29T11:39:52.2133065";
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                try {
                    Date date = dateFormat.parse(dateString);
                    dateFormat.format(date);
                    Log.e("Log",""+dateFormat.format(date));
                } catch (ParseException e)  {           
                        Log.e("GridActivity", "Unable to parse date " + e);
                }
Mujammil Ahamed
  • 1,454
  • 4
  • 24
  • 50