user3401369 user3401369 -5 years ago 189
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?

Answer Source

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) {            
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download