Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format date string in java? [duplicate]

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

like image 267
sad tater Avatar asked Jun 15 '12 07:06

sad tater


People also ask

How do you format a date in java?

Java SimpleDateFormat with Locale String pattern = "EEEEE MMMMM yyyy HH:mm:ss. SSSZ"; SimpleDateFormat simpleDateFormat =new SimpleDateFormat(pattern, new Locale("fr", "FR")); String date = simpleDateFormat. format(new Date()); System.


2 Answers

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); 
like image 89
Keppil Avatar answered Oct 11 '22 04:10

Keppil


use SimpleDateFormat to first parse() String to Date and then format() Date to String

like image 20
jmj Avatar answered Oct 11 '22 03:10

jmj