Link to home
Start Free TrialLog in
Avatar of zumpoof
zumpoof

asked on

Epoch seconds to "10 seconds ago", "2 minutes ago", "4 hours ago", etc

I'd like to be able to convert epoch seconds values into strings like:

"10 seconds ago"
"2 minutes ago"
"1 hour ago"
"4 days ago"
"3 weeks ago"
"2 months ago"

Can someone post the code to do this, or perhaps point me to a library that does this?

Thanks,
Zumpoof
ASKER CERTIFIED SOLUTION
Avatar of mjcoyne
mjcoyne

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This should help, but it wont work out if seconds are singular or plural etc
http://search.cpan.org/~msergeant/Time-Piece-1.11/Seconds.pm
Avatar of mjcoyne
mjcoyne

In the Date::Manip documentation, see especially the Delta_Format section, where you can express, say, 120 seconds in terms of minutes, and so on...
Avatar of ozo
Will you ever want strings like "1 hour and 10 seconds ago"?
Do you want to be able to define when we want to switch from using one unit to using another?
Avatar of zumpoof

ASKER

Ozo,

I just need it to be an approximation. The list I gave above is about as specific as I'd need.