title: Implementing Instagram-like time formatting with Joda-Time
body: <p>If there isn't an easy way currently, I'll just build out the functionality, but I'm new to Joda-Time and was wondering if there is a simple way to do this:</p>
  
  <p>Basically, you have a <code>time</code> in ISO8601 format, and you create a <code>new DateTime(time);</code> using Joda-Time.</p>
  
  <p>Now, if the time was 5 seconds ago, I'd like it to read "5s", if it was 10 minutes ago, "10m", 17 hours ago, "17h", 3 weeks ago, "3w".</p>
  
  <p>Clearly, if something was written 79 seconds ago, it realizes that this is more than 1 minute, and instead opts to check this in minutes, and instead says "1m" instead of "79s".</p>
  
  <p><strong>Update:</strong></p>
  
  <p>So far, my quick solution is this:</p>
  
  <pre><code>public void setTimestamp() {
          DateTime now = DateTime.now();
          if (DateTimeComparator.getInstance().compare(timeCreated, now.minusSeconds(1)) == 1) {
             timestamp = "1s";
          } else if (DateTimeComparator.getInstance().compare(timeCreated, now.minusMinutes(1)) == 1) {
              timestamp = Seconds.secondsBetween(timeCreated, now).getSeconds() + "s";
          } else if (DateTimeComparator.getInstance().compare(timeCreated, now.minusHours(1)) == 1) {
              timestamp = Minutes.minutesBetween(timeCreated, now).getMinutes() + "m";
          } else if (DateTimeComparator.getInstance().compare(timeCreated, now.minusDays(1)) == 1) {
              timestamp = Hours.hoursBetween(timeCreated, now).getHours() + "h";
          } else if (DateTimeComparator.getInstance().compare(timeCreated, now.minusWeeks(1)) == 1) {
              timestamp = Days.daysBetween(timeCreated, now).getDays() + "d";
          } else if (DateTimeComparator.getInstance().compare(timeCreated, now.minusYears(1)) == 1) {
              timestamp = Weeks.weeksBetween(timeCreated, now).getWeeks() + "w";
          } else {
              timestamp = Years.yearsBetween(timeCreated, now).getYears() + "y";
          }
  }
  </code></pre>
  
  <p>It still requires some testing, but from first looks, it seems to work.</p>