Note that there are some explanatory texts on larger screens.

plurals
  1. POJoda-Time: Formatting with multiple formats with single Formatter
    primarykey
    data
    text
    <p>I'd like to print durations given in milliseconds with different format specification depending on its size:</p> <pre><code>case (1) "H:mm" if duration &lt; 10 hours case (2) "HH:mm" if duration &lt; 24 hours case (3) "#d HH:mm" else (duration &gt;= 24 hours) </code></pre> <p>which means only 1 hour field digit for durations lower than 10 hours,<br>but 2 hour field digits when having a leading day field!</p> <p>Examples:</p> <pre><code>case (1) "0:45" means 45 minutes, "1:23" means 1 hour and 23 minutes, case (2) "12:05" means 12 hours and 5 minutes and case (3) "1d 05:09" means 1 day, 5 hours and 9 minutes (= 29 hours and 9 minutes). </code></pre> <p>I had tried with</p> <pre><code>object JodaTest { import org.joda.time._ private val pdf = { import format._ val pfb = new PeriodFormatterBuilder() .appendDays.appendSeparator("d ") .printZeroAlways .minimumPrintedDigits(2).appendHours.appendSeparator(":") .appendMinutes new PeriodFormatter(pfb.toPrinter, null) } def durstr(duration: Long): String = pdf.print((new Period(duration)).normalizedStandard) } </code></pre> <p>which leads to</p> <pre><code> 2700000 =&gt; "00:45" but should be "0:45" 4980000 =&gt; "01:23" but should be "1:23" 43500000 =&gt; "12:05" 104940000 =&gt; "1d 05:09" </code></pre> <p>but I don't know how to omit leading zero of two-digit-day-representation in case (1) but simultaneously force to print it in case (3) with same PeriodFormat.</p> <p>Is it possible to do that with a single <code>org.joda.time.format.PeriodFormatter</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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