Search code examples
javascriptmomentjsiso

Moment.js ISO Time to 2019-03-11T10:05:38+01:00 to relative time


I'm trying to pass an ISO time like "2019-03-12T09:05:38+01:00" to Moment.js.

 moment()
      .startOf("2019-03-12T09:05:38+01:00")
      .fromNow()

I always get "few seconds ago" in console tho. What I'd like to get is stuff like "1 hour ago", "1 day ago" etc. Someone know what I'm doing wrong? Thank you


Solution

  • Try this solution:

    moment("2019-03-12T09:05:38+01:00").fromNow()
    

    Pass ISO date to moment constructor and then get relative time.