Date difference in Javascript (ignoring time of day)

前端 未结 15 2357
无人共我
无人共我 2020-11-27 15:35

I\'m writing an equipment rental application where clients are charged a fee for renting equipment based on the duration (in days) of the rental. So, basically, (daily fee *

15条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:10

    I know this is a partial solution but you may be able to get the days between dates (as long as the dates don't have time set). Then you can work from there.

    I'm basing this solution with the problem you presented ((daily fee * number of days) = total charge); not the actual date difference question. This should help you out.

    var Main = function() {
        var startDate = new Date('08/20/2014');
        var endDate = new Date('08/22/2014');
        var totalCharge = monthlyFee * daysBetween(startDate, endDate);
    }
    
    var daysBetween = function(startDate, endDate) {
        return Math.round(Math.abs((startDate.getTime() - endDate.getTime())/(24*60*60*1000)));
    };
    

提交回复
热议问题