Rails provides a timestamp like follows: 2012-12-21T01:09:32Z
How can I use JavaScript to determine how many days old the timestamp is?
Thanks
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.
You can use
new Date('2012-12-21T01:09:32Z')to turn the string into a Date object. Then use simple arithmetic:You may want to use
Math.floor(daysAgo)orMath.ceil(daysAgo)to round the results down or up, depending on your situation.