Moment.js - Parse Date Time Ago

Dng picture Dng · Oct 27, 2018 · Viewed 25.9k times · Source

I am saving my date like this in my mongo database:

Thu Oct 25 2018 17:30:03 GMT+0300 (EAT) 

I would like to use moment.js to have in the front end like 1 hour ago or 3 hours ago. How would I go about this?

Answer

Paweł picture Paweł · Oct 27, 2018

If you're using single locale try

moment('Thu Oct 25 2018 17:30:03 GMT+0300').fromNow(); //eg. 1 day ago, 2 hours ago etc

or

moment('Thu Oct 25 2018 17:30:03 GMT+0300').fromNow(true); //eg. 1 day, 2 hours

for more see docs

and:

enter image description here