나는 127 초의 동영상을 가지고 있습니다. 02:07
으로 표시하고 싶습니다. 이것을 구현하는 가장 좋은 방법은 무엇입니까?JodaTime 재생 시간을 문자열로 변환
22
A
답변
29
Duration yourDuration = //...
Period period = yourDuration.toPeriod();
PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder()
.printZeroAlways()
.appendMinutes()
.appendSeparator(":")
.appendSeconds()
.toFormatter();
String result = minutesAndSeconds.print(period);
21
나는 이걸 원했고 정확한 llyas 대답을 찾지 못했습니다. 카운터를 갖고 싶습니다. 0 시간 1 분이 지났을 때 0:1
의 답변을 얻었습니다. 그러나 이것은 한 줄의 코드로 쉽게 해결됩니다!
Period p = time.toPeriod();
PeriodFormatter hm = new PeriodFormatterBuilder()
.printZeroAlways()
.minimumPrintedDigits(2) // gives the '01'
.appendHours()
.appendSeparator(":")
.appendMinutes()
.toFormatter();
String result = hm.print(p);
이것은 당신에게 02:07
을 줄 것입니다!
+1
이것은 더 잘 작동하는 것처럼 보이고 받아 들여지는 대답에 우선권으로 upvote –
+0
나는 Brian과 동의한다,'minimumPrintedDigits (2)'는 나가 필요로 한 무엇 정확하게이었다. –
임시로 이것을'org.apache.commons.lang.time.DurationFormatUtils'로 구현했습니다. –
관련 항목 : http://stackoverflow.com/questions/1440557/joda-time-period-to-string – ripper234