Parse A Date From A Timestamp
If you are given a timestamp (seconds since the Unix epoch) and you try to parse it with JavaScript's new Date()
, you are going to get a suprising result.
1970? I was expected something more in the current millenia.
This is because JavaScript's new Date()
expects a timestamp to be in milliseconds. Passing in a seconds representation of a timestamp, when it should be milliseconds, is going to result in a time pretty near the original Unix epoch.
Instead what you need to do is multiple that seconds value by 1000
to get it in terms of milliseconds.
Also, notice that if I run + new Date()
without any argument, it provides the current timestamp in milliseconds.
Last updated