最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

postgresql - Convert postgres timestamp (+ timezone) to Date object [Javascript] - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 11
new Date(dateString.replace(' ', 'T'));

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

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

发布评论

评论列表(0)

  1. 暂无评论