I’m looking for a nice JS snippet to convert a timestamp (e.g. from Twitter API) to a nice user friendly relative time (e.g. 2 seconds ago, one week ago etc).
Anyone care to share some of their favourite methods (preferably not using plugins)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well it’s pretty easy if you aren’t overly concerned with accuracy. What wrong with the trivial method?
Working example here.
You might want to tweak it to handle the singular values better (e.g.
1 dayinstead of1 days) if that bothers you.