Question

I'm facing difficulties to show the time time difference in hours where hours are greater than 24. Right now I'm using the following in iReport

(new SimpleDateFormat("dd':'HH':'mm':'ss")).format(new Date($V{avgDuration}.longValue()*1000))

where $V{avgDuration} is a variable in jrxml file which is the average time difference between two dates in seconds. Here it shows the 1 day 1 hour but I want it to be 25 hour. What should I do?

Was it helpful?

Solution

I've solved the problem using PeriodFormatterBuilder. But for this, I need to use joda-time library.

In the expression editor of the text box in jrxml file, just wrote the following:

new org.joda.time.format.PeriodFormatterBuilder()
        .printZeroAlways()
        .minimumPrintedDigits(2)
        .appendHours().appendSeparator(":")
        .appendMinutes().appendSeparator(":")
        .appendSeconds()
        .toFormatter()
        .print(new org.joda.time.Period(
            $V{avgDuration}.longValue()*1000))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top