Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><sup><em>Since everyone shouts "YOODAA!!!" but noone posts a concrete example, here's my contribution.</em></sup></p> <p>You could also do this with <a href="http://www.joda.org/joda-time/" rel="noreferrer">Joda-Time</a>. Use <a href="http://www.joda.org/joda-time/apidocs/org/joda/time/Period.html" rel="noreferrer"><code>Period</code></a> to represent a period. To format the period in the desired human representation, use <a href="http://www.joda.org/joda-time/apidocs/org/joda/time/format/PeriodFormatter.html" rel="noreferrer"><code>PeriodFormatter</code></a> which you can build by <a href="http://www.joda.org/joda-time/apidocs/org/joda/time/format/PeriodFormatterBuilder.html" rel="noreferrer"><code>PeriodFormatterBuilder</code></a>.</p> <p>Here's a kickoff example:</p> <pre><code>DateTime myBirthDate = new DateTime(1978, 3, 26, 12, 35, 0, 0); DateTime now = new DateTime(); Period period = new Period(myBirthDate, now); PeriodFormatter formatter = new PeriodFormatterBuilder() .appendYears().appendSuffix(" year, ", " years, ") .appendMonths().appendSuffix(" month, ", " months, ") .appendWeeks().appendSuffix(" week, ", " weeks, ") .appendDays().appendSuffix(" day, ", " days, ") .appendHours().appendSuffix(" hour, ", " hours, ") .appendMinutes().appendSuffix(" minute, ", " minutes, ") .appendSeconds().appendSuffix(" second", " seconds") .printZeroNever() .toFormatter(); String elapsed = formatter.print(period); System.out.println(elapsed + " ago"); </code></pre> <p>Much more clear and concise, isn't it? </p> <p>This prints by now </p> <pre> 32 years, 1 month, 1 week, 5 days, 6 hours, 56 minutes, 24 seconds ago </pre> <p><sup><sub>(Cough, old, cough)</sub></sup> </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