-3

I want to implement in my app date and time standards like facebook does for example:

post from x minust ago shows as: X mins
post from x seconds ago shows as: X secs
.....
post from yesterday shows as: yestarday at 7:22pm
post from last month shows as: june 15 ...

I am searching for the full timestamp dictinary that convert's datetime to string facebook X time ago

CBroe
  • 91,630
  • 14
  • 92
  • 150
shay
  • 2,021
  • 1
  • 15
  • 17

1 Answers1

1

How to calculate "time ago" in Java?

Take a look at the PrettyTime library.

It's quite simple to use:

import org.ocpsoft.prettytime.PrettyTime;

PrettyTime p = new PrettyTime();
System.out.println(p.format(new Date()));
// prints "moments ago"

You can also pass in a locale for internationalized messages:

PrettyTime p = new PrettyTime(new Locale("fr"));
System.out.println(p.format(new Date()));
// prints "à l'instant"

As noted in the comments, Android has this functionality built into the android.text.format.DateUtils class.

Community
  • 1
  • 1
Ian
  • 159
  • 4