Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Change Date Format

Unparseable date: "20/02/2014"

I have date "20/02/2014" in String format and want to change it's format to "MMMM dd,yyyy" but it gives error.

Here is the code:

  try {
    SimpleDateFormat df = new SimpleDateFormat("MMMM dd,yyyy");
     Date date = df.parse("20/02/2014"); 
    System.out.println(date); 
} catch (ParseException e) {  

    e.printStackTrace();  
} catch (java.text.ParseException e) {
    e.printStackTrace();
}
like image 839
Naveed Ali Avatar asked Jan 18 '26 23:01

Naveed Ali


1 Answers

try this code :

try {
          String str = "20/02/2014";
          SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy");
          SimpleDateFormat sdf2 = new SimpleDateFormat("MMMM dd,yyyy");

          System.out.println("Formatted Date : "+sdf2.format(sdf1.parse(str)));       } catch (Exception e) {
      e.printStackTrace();        }
like image 168
Vijju Avatar answered Jan 21 '26 09:01

Vijju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!