2014-03-12 28 views
-1

的期限内假日数需要2个Date对象的分化..使用jQuery的2日期之间的区别? calcualate时间

需要根据工作的总天数或工作betn的日期1的总时数来计算成本和date2

还需要calcualate在一段时间内的假期数量!

$(document).ready(function() { 
    $('#CostMaster_labour_deallocationdate').change(function(){ 
     var date1 = $('#CostMaster_labour_deallocationdate1').val(); 
     var date2 = $('#CostMaster_labour_deallocationdate').val(); 
    }); 
}); 
+0

http://stackoverflow.com/questions/2609513/jquery-calculate-day-difference-in-2-date-textboxes – halkujabra

回答

1

使用下面的JavaScript功能::

function CheckDateDifference() { 
     var date1 = $('#CostMaster_labour_deallocationdate1').val(); 
     var date2 = $('#CostMaster_labour_deallocationdate').val(); 
     var diff = Math.round((date1 - date2)/1000/60/60/24); 
     return diff; 
    }; 
+0

不工作..忘记NaN值 – user3378215

0

1.Try使用datejs framework轻松地完成所有的日期时间计算。

2.Else试试这个

function DateDiff(var /*Date*/ date1, var /*Date*/ date2) { 
    return date1.getTime() - date2.getTime(); 
} 

这将返回两个日期之间的毫秒差数。将其转换为秒,分钟,小时等不应太困难。

相关问题