Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>Period</code> formatting is done by the <a href="http://joda-time.sourceforge.net/api-release/org/joda/time/format/PeriodFormatter.html">PeriodFormatter</a> class. You can use a default one, or construct your own using <a href="http://joda-time.sourceforge.net/api-release/org/joda/time/format/PeriodFormatterBuilder.html">PeriodFormatterBuilder</a>. It may take some more code as you might like to set this builder up properly, but you can use it for example like so:</p> <pre><code> scala> import org.joda.time._ import org.joda.time._ scala> import org.joda.time.format._ import org.joda.time.format._ scala> val d1 = new DateTime(2010,1,1,10,5,1,0) d1: org.joda.time.DateTime = 2010-01-01T10:05:01.000+01:00 scala> val d2 = new DateTime(2010,1,1,13,7,2,0) d2: org.joda.time.DateTime = 2010-01-01T13:07:02.000+01:00 scala> val p = new Period(d1, d2) p: org.joda.time.Period = PT3H2M1S scala> val hms = new PeriodFormatterBuilder() minimumPrintedDigits(2) printZeroAlways() appendHours() appendSeparator(":") appendMinutes() appendSuffix(":") appendSeconds() toFormatter hms: org.joda.time.format.PeriodFormatter = org.joda.time.format.PeriodFormatter@4d2125 scala> hms print p res0: java.lang.String = 03:02:01 </code></pre> <p>You should perhaps also be aware that day transitions are not taken into account:</p> <pre><code> scala> val p2 = new Period(new LocalDate(2010,1,1), new LocalDate(2010,1,2)) p2: org.joda.time.Period = P1D scala> hms print p2 res1: java.lang.String = 00:00:00 </code></pre> <p>so if you need to hanldes those as well, you would also need to add the required fields (days, weeks, years maybe) to the formatter.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload