user3401369 user3401369 - 4 months ago 8x
Java Question

Android: How to convert string into date

I am currently working on a calendar application using Caldroid and the date that Caldroid returns looks like this:

Fri Jun 17 12:31:00 GMT+07:00 2016

I just need to extract the date from it like for example:


How am I supposed to do that?


Try this -

    DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
    DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy");

    try {
        //This will give you the desired output
        df2.format(df.parse("Fri Jun 17 12:31:00 GMT+07:00 2016"));
    } catch (ParseException e) {