Convert postgres timestamp (+ timezone) to Date object [Javascript]
13,973
Solution 1
I needed to use moment(some_date).fromNow()
Instead of moment.startOf(some_date).fromNow()
Solution 2
new Date(dateString.replace(' ', 'T'));
Author by
Trevor
Updated on June 15, 2022Comments
-
Trevor almost 2 years
Our postgres database returns a string with a timestamp:
'2016-07-24T03:32:45.678Z'
We are trying to use the
moment.js
library, but it only accepts a Date object.How can I convert the above timestamp+timezone into a Date object using Javascript?
Thank you for any help you can provide.