Код: Выделить всё
new DateTimeFormatterBuilder()
.optionalStart()
.appendValue(HOUR_OF_DAY, 1, 2, SignStyle.NOT_NEGATIVE)
.appendLiteral(':')
.optionalEnd()
.appendValue(MINUTE_OF_HOUR, 2)
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.appendFraction(NANO_OF_SECOND, 0, 9, true)
.toFormatter()
.withResolverStyle(STRICT);
//the duration is created like this
return Duration.between(LocalTime.MIN, LocalTime.parse(formatted, formatter));
Код: Выделить всё
12:34:56.789
2:34:56.789
34:56.789
34:56 (mm:ss not hh:mm)
Как создать форматтер, который пройдет все 4 теста?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -formatter