How do I create default a ZonedDateTime to midnight if HH:mm:ss is not defined?

Viewed 812

Here's what I'm trying to do:

public ZonedDateTime getZdt(String myDate, String format) {
    return  ZonedDateTime.parse(
                myDate,   
                DateTimeFormatter.ofPattern(format)
                    .withZone(ZoneId.systemDefault())
            );
}

getZdt("17-05-2017 00:10:59", "dd-MM-yyyy HH:mm:ss") //works fine
getZdt("17-05-2017", "dd-MM-yyyy") //DateTimeParseException (...Unable to obtain LocalTime from TemporalAccessor:) 

What I'm trying to do is pretty simple. How do I get this to work?

3 Answers
Related