Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the time until next Sunday with moment.js

Tags:

momentjs

So I have moment JS, 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.

Moment has a from method but not an until method.

like image 614
alt Avatar asked Jul 17 '13 04:07

alt


Video Answer


2 Answers

There's a function moment.fromNow() which shows things like "in 5 months" or "3 years ago".

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

like image 193
frabcus Avatar answered Dec 17 '22 22:12

frabcus


why don't you try moment#to

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

as for the next sunday,

moment().endOf("week"); 

might do the trick.

so basically the code you would require will be

var now = moment();
var nextSunday = moment().endOf("week");
now.to(nextSunday)
like image 39
Noushad Avatar answered Dec 17 '22 23:12

Noushad