0

Besides:

Date.parse(timestampString)

and

new Date(timestampString).getTime()

???

I am running some benchmarks, and trying to find the fastest/most efficient way to convert a timestamp like '2021-08-07 03:32:05.387089' to 1628321525387.

  • Your biggest issue is using the built–in parser, see [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) Writing your own parse function will likely be faster than using a library. – RobG Aug 09 '21 at 20:15

1 Answers1

0

tl;dr new Date().valueOf()

There is another option: new Date(timestampString).valueOf()

Here you have benchmark valueOf() vs getTime()

Veter
  • 532
  • 2
  • 10
  • `+new Date()` is faster, but the issue here is using the built–in parser for an unsupported format is flawed in the first place. A robust parse will take very much longer than the conversion to number, so the OP is focusing on the wrong issue. – RobG Aug 09 '21 at 20:16