0

I have string date 2020-07-05 22:44:59 in string format, I parse it with SimpleDateFormat with "yyyy-MM-dd HH:mm:ss a z" date pattern but it gives me date like Sun Jul 05 22:44:59 IST 2020. So how I can get date in "yyyy-MM-dd HH:mm:ss a z" format in date object.

Input : 2020-07-05 22:44:59 Output : 2020-07-05 22:44:59

I want output int the same format like input.

Thanks for Helping me.

Rahul Sharma
  • 47
  • 1
  • 10
  • 1
    Does this answer your question? [Java convert date format](https://stackoverflow.com/questions/31624828/java-convert-date-format) – Draken Jul 08 '20 at 06:41
  • I recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `LocalDateTime` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Jul 08 '20 at 17:54

1 Answers1

0
String input = "2020-07-05 22:44:59";
DateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = parser.parse(input);
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String output = formatter.format(date);
bigbounty
  • 16,526
  • 5
  • 37
  • 65