How to get date and time in below format in java?

258 Views Asked by At

How can I get the current date and time and how can I transfer it into the following String format?

06-04-2020 05:00 PM

After that I need to add few minutes to the date? Please help!

2

There are 2 best solutions below

7
On BEST ANSWER

Your answer should look something like this:

String dateTimePattern = "dd-MM-yyyy HH:mm a";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimePattern );
LocalDateTime yourDay= LocalDateTime.of(2020, 4, 6, 17, 00);
System.out.println(formatter.format(ZonedDateTime.of(yourDay, ZoneId.of("UTC-5"))));

Please look this up for more info on the available formats.

1
On
Date yourDate = new Date();  
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy h:m a");  
String formatedDate= sdf.format(yourDate);