I'd like to display some dates as relative to the current date in a human-friendly format.
Examples of human-friendly relative dates:
- 10 seconds ago
- 20 minutes from now
- 1 day ago
- 5 weeks ago
- 2 months ago
Basically faithfully preserving the highest order of magnitude (and by preference, only shifting up units when passing 2 of those units - 5 weeks instead of 1 month).
Though I could live with a library that had less control and even more friendly dates like:
- yesterday
- tomorrow
- last week
- a few minutes ago
- in a couple hours
Any popular libraries for this?
here an example of sugar vs moment: for a calendar that displays weeks, I needed the last monday value:
moment.js
sugar.js
I much prefer sugar and after some months with moment.js now switch to sugar.js. it is clearer and integrates nicely with Javascripts' Date class.
OP cases are covered by both libs, for sugar.js see http://sugarjs.com/dates