java - How to calculate elapsed time from now with Joda-Time? -


I need to compute the duration of a specific date so far and it's the same Display the form as StackOverflow queries, that is:

  15 seconds ago 2 minutes ago 2 hours ago 2 days ago 25 December 08  

Know how to get it with Java library ? Is there a helpful method, which already applies to it, or should I write algorithms?

To calculate the time elapsed with judetime, use. To format the time elapsed in the desired human representation, use it that you can create.

Here is a kickoff example:

  date time myBirthDate = new date time (1978, 3, 26, 12, 35, 0, 0); Date time = new date time (); Period duration = new period (microddate, now); Adendesfix ("min before \ n") .appendHours () .andandfix ("hours ago \ n"). Apfixfix ("seconds ago \ n"). Endandsfix ("seconds ago \ n"). Ependuffix ("Day before \ n"). Append Weeks ("Week before \ n"). Endendphx (). Endendix ("month ago \ n") .appdirectories () .AndxSex ("years ago \ n") .printZeroNever () .toFormatter () ; String passed = formatter.print (period); Println (eloquent); 

3 seconds ago 51 minutes ago 7 hours ago 6 days ago 10 months ago 31 years ago

(Cough, old man, cough) You see that I have taken months and years to account and have configured it to leave zero values.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -