We help IT Professionals succeed at work.

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

zumpoof
zumpoof asked
on
280 Views
Last Modified: 2010-03-05
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
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Kim RyanIT Consultant

Commented:
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

Commented:
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...
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
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?

Author

Commented:
Ozo,

I just need it to be an approximation. The list I gave above is about as specific as I'd need.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.