AskingToStack AskingToStack - 1 year ago 81
Android Question

Converting Date "2016-06-03" to "03 JUNE 2016" in Android

I have date format as

and I have to convert it as below :

"03 JUNE 2016"

I have tried as below :

SimpleDateFormat formatter = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH);
String newFormat = formatter.format("2016-06-03");

But, getting below error :

Invalid Arguments Exception

Please, help me to solve out this. Thanks.

Answer Source

Try This common function for convert date format

public static SimpleDateFormat targetFormat = new SimpleDateFormat();
public static SimpleDateFormat originalFormat = new SimpleDateFormat();
public static String formattedDate = "";

public static String getFormattedDate(String targetPattern,
                                      String existingPattern, String existingValue) {
    formattedDate = existingValue;
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
    symbols.setAmPmStrings(new String[] { "AM", "PM" });
    try {
        formattedDate = targetFormat.format(originalFormat
    } catch (ParseException e) {
        // TODO Auto-generated catch block
    return formattedDate;

and used like

 String txtdate = getFormattedDate("dd MMMM yyyy","yyyy-MM-dd","2016-06-03");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download