Reputation: 18200
If you have an old UNIX timestamp in JavaScript... is there a way I can get the number of the age of that timestamp?
Like, the age of how old that unix timestamp is from when it is... to now.
Can you do that in JavaScript?
Upvotes: 2
Views: 4116
Reputation:
Assuming your timestamp is in milliseconds, you can get the the age in milliseconds using:
(new Date()).getTime() - timestamp;
If your timestamp is in seconds, multiply it by 1000 before subtracting.
You can then divide by the appropriate factor to convert to seconds/minutes/hours etc. For example, to get the age in years, you would use:
((new Date()).getTime() - timestamp) / (1000 * 60 * 60 * 24 * 365);
Upvotes: 13