Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert postgres timestamp (+ timezone) to Date object [Javascript]

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.

like image 547
Trevor Avatar asked Jul 24 '16 04:07

Trevor


2 Answers

new Date(dateString.replace(' ', 'T'));
like image 92
Tarun Dugar Avatar answered Oct 07 '22 18:10

Tarun Dugar


I needed to use moment(some_date).fromNow()

Instead of moment.startOf(some_date).fromNow()

like image 34
Trevor Avatar answered Oct 07 '22 16:10

Trevor