更新时间:2023-11-23 11:09:16
这应该是窍门
var start = $('#start_date')。val();
var end = $('#end_date')。val();
// end - start以毫秒为单位返回差异
var diff = new Date(end-start);
// get days
var days = diff / 1000/60/60/24;
示例
var start = new Date(2010-04-01),
end = new Date(),
diff = new Date(end-start),
days = diff / 1000/60/60/24;
天; // => 8.525845775462964
HI Guys,
I have 2 asp.net texboxes with calendar extender. i want to find out the number of days between both dates when one of the date control is changed. how can i achieve this using jquery or javascript ?
This should do the trick
var start = $('#start_date').val();
var end = $('#end_date').val();
// end - start returns difference in milliseconds
var diff = new Date(end - start);
// get days
var days = diff/1000/60/60/24;
Example
var start = new Date("2010-04-01"),
end = new Date(),
diff = new Date(end - start),
days = diff/1000/60/60/24;
days; //=> 8.525845775462964