Search code examples
javadatetime-formatcurrent-time

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


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!


Solution

  • 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.