Moment.js - two dates difference in number of days

后端 未结 6 2121
不知归路
不知归路 2020-12-03 06:14

I get incorrect results when trying to find numeric difference between two dates:

var startDate = moment( $(\'[name=\"date-start\"]\').val(), \"DD.MM.YYYY\")         


        
6条回答
  •  隐瞒了意图╮
    2020-12-03 07:15

    the diff method returns the difference in milliseconds. Instantiating moment(diff) isn't meaningful.

    You can define a variable :

    var dayInMilliseconds = 1000 * 60 * 60 * 24;
    

    and then use it like so :

    diff / dayInMilliseconds // --> 15
    

    Edit

    actually, this is built into the diff method, dubes' answer is better

提交回复
热议问题