Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 Time API: how to parse string of format “mm:ss” to Duration?

I tried to use DateTimeFormatter for it, but not found way. Duration.parse("") only use special format.

like image 272
roman-v1 Avatar asked Jul 08 '14 22:07

roman-v1


1 Answers

You can parse the String yourself and reformat it into the format required by Duration

String value = ... //mm:ss
String[] fields = value.split(":");
return Duration.parse(String.format("P%dM%sS", fields[0], fields[1]));
like image 147
dkatzel Avatar answered Sep 19 '22 18:09

dkatzel