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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With