Number of days between two dates in ISO8601 date format

后端 未结 4 430
谎友^
谎友^ 2021-01-14 17:29

I want to do same thing as How do I get the number of days between two dates in JavaScript?

but I want do the same on this date format: 2000-12-31.

4条回答
  •  遥遥无期
    2021-01-14 17:52

    Try this.

    var toDate = "2000-12-31";
    var fromDate = "2000-10-30";
    var diff =  Math.floor(( Date.parse(toDate) - Date.parse(fromDate) ) / 86400000);
    

    You wont be asking this question if you have checked the answer with more up-votes and not the marked answer on the link you have provided. :)

提交回复
热议问题