How to combine date and time into a single object?

You just need to use the correct methods, instead of calling constructors. Use parse to create local date and local time objects, then pass the two objects to the of method of LocalDateTime:

    LocalDate datePart = LocalDate.parse("2013-01-02");
    LocalTime timePart = LocalTime.parse("04:05:06");
    LocalDateTime dt = LocalDateTime.of(datePart, timePart);


Apparently, you need to combine two Date objects instead of 2 strings. I guess you can first convert the two dates to strings using SimpleDateFormat. Then use the methods shown above.

String startingDate = new SimpleDateFormat("yyyy-MM-dd").format(startDate);
String startingTime = new SimpleDateFormat("hh:mm:ss").format(startTime);

Leave a Comment