I have a field in a form to state the time duration of an event. Say, the event is to last 15 mins. So the field will have the following value: 00:15 If it is to last 1 hour
I think a better way would be to use PeriodFormatterBuilder like this:
PeriodFormatter hoursMinutes= new PeriodFormatterBuilder()
.appendHours()
.appendSeparator(":")
.appendMinutes()
.toFormatter();
Then you can parse your strings into Period
objects and call toStandardDuration()
on those - or keep working with the Period
, since that seems to match your use case better.