0

I have two dates of type String, the first in the format "yyyy.MM.dd", the second "HH: mm"

They converted them to a Date type using SimpleDateFormat;

So, I need to put them together, that is, the result should be "yyyy.MM.dd HH: mm" Are there other options for how to add them, except

date.setHours();
date.setMinutes();
DevOma
  • 299
  • 1
  • 4
  • 17

1 Answers1

0

You can use "java.time.LocalDateTime". This also allows you to format with java.time.format.DateTimeFormatter.

Example program:

public static void main(String[] args) {
        LocalDate date = LocalDate.of(2013, 1, 2);
        LocalTime time = LocalTime.of(4, 5, 6);
        LocalDateTime localDateTime = LocalDateTime.of(date, time);
        DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM d yyyy  hh:mm a");
        System.out.println(localDateTime.format(format));
    }
Dsenese1
  • 1,106
  • 10
  • 18