Date difference in Javascript (ignoring time of day)

前端 未结 15 2368
无人共我
无人共我 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

    Since the Julian day is effectively the number of days (and in some cases also the fraction of number of days) since a certain date, it is practically the same as a UNIX timestamp, presented differently. You can get the number of whole days since 1970 like so:

    Date.prototype.getWholeDays = function () {
        return Math.floor(new Date() / 1000*60*60*24);
    };
    
    function dateDiff(startDate, endDate) {
        return endDate.getWholeDays() - startDate.getWholeDays();
    }
    

提交回复
热议问题