選擇我有3個文本字段中導軌通過從pickadate選擇日期查看計算數量通過pickadate在jquery的
<div>
<%= f.label :from_date %>
<%= f.text_field :start_date, :class => 'datepicker' %>
</div>
<div>
<%= f.label :to_date %>
<%= f.text_field :end_date, :class => 'datepicker' %>
</div>
<div>
<label>Days</label
<%= f.text_field :days,:readonly => true %>
</div>
。在application.js中 MT代碼:
$('.datepicker).pickadate();
我想計算日期之間的天數。我的計算方法定義如下: -
function calculate() {
var d1 = $('#startdate').pickadate('getDate');
var d2 = $('#enddate').pickadate('getDate');
var diff = 1;
if (d1 && d2) {
diff = diff + Math.floor((d2.getTime() - d1.getTime())/86400000);
}
$('#days').val(diff);
}
但它不能正常工作有一些缺失。我沒有得到它。請幫幫我。提前致謝。
這個Q/A的可能重複http://stackoverflow.com/questions/542938/how-do-i-get-the-number-of-days-between-two-dates-in-javascript?answertab=有源#製表頂 –