I'm looking for a PHP library that generates user-friendly representations of times - for example "two hours ago" when the timestamp is time() - 2 * 3600
.
There are several existing questions with answers and blog posts (1, 2, 3), but all only contain code snippets - not a library I can install and upgrade.
Django has one, Python also has a standalone lib, Javascript has several (1, 2, 3), too - where is the PHP library?
A library should have the following things:
Since there didn't seem to be any library, I've made one myself and got it included in PEAR:
Date_HumanDiff, http://pear.php.net/package/Date_HumanDiff
Code is at http://github.com/pear/Date_HumanDiff
I know Kohana has one, you can propably port it easily.
The function is called fuzzy_span()
.
See http://kohanaframework.org/3.3/guide-api/Date#fuzzy_span
Kohana Date class provides fuzzy_span()
method for this. But it can't reply you exact values like "10 minutes"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With