ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 253 forks source link

Just get "Days Ago" #178

Closed HermanKayy closed 3 years ago

HermanKayy commented 4 years ago

Is there a way to just get back "Days Ago"? For example if it's 7 days instead of it giving me back "1 week" ago it'll give me back 7 days ago. Instead of 1 month ago it'll give me back 30 days ago, etc.

lincolnthree commented 3 years ago

@HermanKayy Yes, you need to manually pass only the Day time unit to the PrettyTime configuration, after removing all others:

PrettyTime p = new PrettyTime();
p.clearUnits();
Day day = new Day();
p.registerUnit(day,  new ResourcesTimeFormat(day));
p.format(new Date());
lincolnthree commented 3 years ago

Working on an easier API for this in Version 5.

lincolnthree commented 3 years ago

New API here: https://github.com/ocpsoft/prettytime/commit/08894358b6b5ee1b587a0527fc42e05b60d1c57b