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.
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.
Share Improve this question asked Jul 24, 2016 at 4:56 TrevorTrevor 1,4143 gold badges16 silver badges33 bronze badges 2- 3 Moment accepts and in fact prefers strings. The best practice with moment is to never use a date object unless it has been given to you by a third party API. MOment should parse this time format by default when you pass it to the moment constructor. – Maggie Pint Commented Jul 24, 2016 at 14:13
- 2 See parsing strings: momentjs.com/docs/#/parsing/string – Maggie Pint Commented Jul 24, 2016 at 14:13
2 Answers
Reset to default 11new Date(dateString.replace(' ', 'T'));
I needed to use moment(some_date).fromNow()
Instead of moment.startOf(some_date).fromNow()