I have a problem with jodatime api. I can not understand why this test does not work. I need to decide how many days, hours, minutes and seconds I have in milliseconds. But the value of the days is not resolved .... any idea?
@Test public void testTime() { long secs = 3866 * 24 * 35; long msecs = secs * 1000; //Period period = duration.toPeriod(); PeriodType periodType = PeriodType.forFields( new DurationFieldType[]{ DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds(), }); Duration duration = Duration.standardSeconds(secs); Period period = duration.toPeriod(periodType, GregorianChronology.getInstance()); System.out.println("days:" + period.getDays()); System.out.println("hours:" + period.getHours()); System.out.println("mins:" + period.getMinutes()); System.out.println("seconds:" + period.getSeconds()); PeriodFormatter periodFormatter = new PeriodFormatterBuilder() .printZeroAlways() .minimumPrintedDigits(2) .appendDays() .appendSeparator(":") .appendHours() .appendSeparator(":") .appendMinutes() .appendSeparator(":") .appendSecondsWithOptionalMillis() .toFormatter(); StringBuffer stringBuffer = new StringBuffer(); periodFormatter.printTo(stringBuffer, period); System.out.println(">>>" + stringBuffer); }
days off: 0 Hours: 902 min: 4 seconds: 0 00: 902: 04: 00
source share