如何计算MaterialiseCSS datepicker中两个日期之间的天数?

时间:2016-07-14 08:59:07

标签: jquery datepicker materialize

我想弄清楚MaterialiseCSS datepicker中两个日期之间的天数。 以下是在jQuery datepicker中工作的那个。

jQuery Datepicker:

var d1 = $('#req_startdate').datepicker('getDate');
var d2 = $('#req_enddate').datepicker('getDate');

if (d1 && d2) {
    diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
    $('#calculated').val(diff);
}

MaterialiseCSS Datepicker:

var d1 = $('#startdate').val();
var d2 = $('#enddate').val();

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

var doc = new jsPDF()
var text = 'This is a text without real content but with 59 characters.'

var lineHeight = doc.getLineHeight(text) / doc.internal.scaleFactor
var splittedText = doc.splitTextToSize(text, 50)
var lines = splittedText.length  // splitted text is a string array
var blockHeight = lines * lineHeight
var yPos = 10
var xPos = 10
doc.text(xPos, yPos, splittedText)
yPos += blockHeight
doc.text(xPos, yPos, '----- This text follows the previous text block.')
yPos += lineHeight
doc.text(xPos, yPos, '----- LineHeight=' + lineHeight + ' / blockHeight=' + blockHeight)
yPos += lineHeight
doc.text(xPos, yPos, '----- doc.internal.scaleFactor = ' + doc.internal.scaleFactor)

注意:相同的代码复制并粘贴并为 txtFromDate

提供其他功能

答案 1 :(得分:0)

通过以下逻辑得到结果:

        var d1 = $('#reqstartdate').val();
        var d2 = $('#reqenddate').val();

        var date1 = new Date(d1);
        var date2 = new Date(d2);

        var date1_ms = date1.getTime();
        var date2_ms = date2.getTime();

        var diff = date2_ms-date1_ms;

          // get days
        var days = diff/1000/60/60/24;

        $('#calculated').val(days);