How to format date string in java?

sad tater picture sad tater · Jun 15, 2012 · Viewed 153.7k times · Source

Hi i have the following string:2012-05-20T09:00:00.000Z and i want to format it to be like 20/05/2012, 9am

How to do so in java?

Thanks

Answer

Keppil picture Keppil · Jun 15, 2012

If you are looking for a solution to your particular case, it would be:

Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse("2012-05-20T09:00:00.000Z");
String formattedDate = new SimpleDateFormat("dd/MM/yyyy, Ka").format(date);