Android Developer Android Developer - 3 months ago 20
Android Question

How to parse Date format server format To "MM/dd/YYYY"

I was found many solution but its not working for me.

I am trying to parse date to user selected date format.

I was getting date from server in this format 2016-06-30T00:00:00Z UTC Timezone

Now I want to Parse it in User selected format for e.g MM/dd/yyyy

How Can i do that.? I was found many solution but its not working for me.

Answer

To get date into a particular format, first you have to parse the date string into it's given format and there you will get Date object. Second, you can convert the date object into a desired format.

private String getFormattedDate(String strDate) {    
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    Date d= (Date)formatter.parse(strDate);

    SimpleDateFormat fmtOut = new SimpleDateFormat("MM/dd/yyyy");
    return fmtOut.format(date);
}