How to convert date time from one format to another in Android?

5.6k views Asked by At

I want to convert date and time from "2014-11-25 14:30" format to " Nov 25th,2014 at 2:30pm ". Could anybody please tell how to do so?

Thanks!

1

There are 1 answers

9
Pratik Dasa On BEST ANSWER

Try with below code:

String date = "2014-11-25 14:30";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:MM");
        Date testDate = null;
        try {
            testDate = sdf.parse(date);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        SimpleDateFormat formatter = new SimpleDateFormat("MMM dd,yyyy hh:mm a");
        String newFormat = formatter.format(testDate);
        System.out.println(".....Date..."+newFormat);