Getting time until next Sunday using the moment. Js

So, I have a JS moment, and I need to display the time until next Sunday in human readable words:

Next Sunday will be in 5 days, 4 hours, 30 minutes, and 10 seconds.

The moment has a from method, but not an until method.

+4
source share
2 answers

There is a moment.fromNow () function here that shows things like "after 5 months" or "3 years ago."

http://momentjs.com/docs/#/displaying/fromnow/

+3
source

why don't you try # moment on

  a.to(b) // "in a day" 

like for next sunday,

 moment().endOf("week"); 

can do the trick.

so basically the code you need will be

 var now = moment(); var nextSunday = moment().endOf("week"); now.to(nextSunday) 
+1
source

Source: https://habr.com/ru/post/1491766/


All Articles