如何从jQuery 1.0中的两个日期获取周数?
我试过这个但没有运气:
//start and end date is in format '10-0ct-2015'
var end = $("span[id$=spEstDeliveryDate] input[type=text]").val();
var start = $("span[id$=spPODeliveryDate] input[type=text]").val();
var f = $.datepicker.parseDate("dd-M-yy", end);
var date1 = new Date(f);
date1 = (date1.getDate() + '/' + (date1.getMonth() + 1 ) + '/' + date1.getFullYear());
f = $.datepicker.parseDate("dd-M-yy", start);
var date2 = new Date(f);
date2 = (date2.getDate() + '/' + (date2.getMonth() + 1) + '/' + date2.getFullYear());
var totalWeeks = Math.floor((date1 - date2 + 1) / (1000 * 60 * 60 * 24) / 7);
答案 0 :(得分:0)
在尝试对它们进行数学运算之前,将日期转换为字符串。将它们保留为Date
个对象:
var f = $.datepicker.parseDate("dd-M-yy", end);
var date1 = new Date(f);
f = $.datepicker.parseDate("dd-M-yy", start);
var date2 = new Date(f);
var totalWeeks = Math.floor((date1 - date2) / (1000 * 60 * 60 * 24) / 7);