2

I don't know what wrong with the below code, but the output is very weird.

My purpose is to get the number of (days, hours, minutes, and seconds) out of the inputted big number of seconds.

int numSeconds = 612372;
// int numSeconds = 898298;
Seconds nSeconds = Seconds.seconds(numSeconds);
Period period = new Period(nSeconds);
PeriodFormatter dhm = new PeriodFormatterBuilder()
.appendDays()
.appendSuffix(" day", " days")
.appendSeparator(", ")
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(", ")
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(", ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();

System.out.println(dhm.print(period.normalizedStandard()));

// very weird output
// 2 hours, 6 minutes, 12 seconds

It should print 7 days, ...blah..blah...

Lii
  • 11,553
  • 8
  • 64
  • 88
varmansvn
  • 63
  • 4
  • possible duplicate of [Joda-Time: Period to string](http://stackoverflow.com/questions/1440557/joda-time-period-to-string) –  Dec 10 '12 at 10:34
  • It's not the duplicate. I already normalize the period before printing it out as as string. – varmansvn Dec 10 '12 at 11:04

1 Answers1

2

I found a way out for this. 3 things to modify.

  1. Period period = new Period(millisecond) // not seconds or micro seconds
  2. period.toStandardDuration().getStandardDays() to get number of days
  3. period.getHours(), period.getMinutes(), period.getSeconds() to get number of hours, minutes, and seconds

I don't know this is right or wrong way, but the result is correct.

Lii
  • 11,553
  • 8
  • 64
  • 88
varmansvn
  • 63
  • 4