Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i convert "2019-07-14T18:30:00.000Z" to "2021-09-26 04:30:00 PM" using DateTimeFormatter or any other library in Java [duplicate]

I am not sure whether this has been already answered or not, but can anyone please tell me how can I convert "2019-07-14T18:30:00.000Z" to "2019-07-14 04:30:00 PM" using DateTimeFormatter or any other library in Java? Basically the output date-time should have time in AM/PM format.

like image 686
Kirti Jha Avatar asked Nov 16 '25 10:11

Kirti Jha


1 Answers

Try this

String date = "2019-07-14T18:30:00.000Z";
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
Date parsedDate = inputFormat.parse(date);
String formattedDate = outputFormat.format(parsedDate);
System.out.println(formattedDate);
like image 144
Taha Avatar answered Nov 18 '25 09:11

Taha



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!