I'm trying to shift datetime by a Duration which I get in the format "HHmm", for example "0010" meaning 10 minutes.
I've found similar ticket (Parsing time strings like "1h 30min") but I can't make it work properly.
Here's the code:
PeriodFormatter hoursMinutes = new PeriodFormatterBuilder().appendHours().appendMinutes().toFormatter();
Duration duration = hoursMinutes.parsePeriod("0010").toStandardDuration();
duration.getStandardMinutes(); //Returns 600
For some reason, I get 600 minutes instead of 10. So it looks like the minutes were interpreted as hours, but I can't understand why. I've tried adding .maximumParsedDigits(2)
for hours, but the result was the same.
Why is my code wrong? Is there some other way to initialize duration parser? Something, where I could just use the standard format like "HHmm"?