jQuery UI Datepicker - 日期之间的天数 [英] jQuery UI Datepicker - Number of Days Between Dates

查看:141
本文介绍了jQuery UI Datepicker - 日期之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery UI Datepicker。我有两个日期字段。我想找到两个日期之间的差异天数。



一旦我有天数,我想把所说的数字放在一个



对这个问题的任何帮助将不胜感激。



干杯。

解决方案

您可以使用 onselect 事件来获取日期。

  $('#date1')。datepicker({
onSelect:function(dateText,inst){
var d1 = new Date(dateText );
//从其他文本字段获取日期
var d2 = new Date($('#date2')。val());
// d2 -d1给出结果毫秒
//通过Math.abs((d2-d1)/ 86400000)计算天数,为24 * 3600 * 1000 = 86400000
//并将其填充到某些文本字段#textfield
$('#textfield')。val((Math.abs((d2-d1)/ 86400000)));
}
});
/ pre>

I am using jQuery UI Datepicker. I have two date fields. I would like to find the number of days difference between the two dates.

Once I have the number of days, I’d like to put said number of dasy into a textfield.

Any help with this issue would be much appreciated.

Cheers.

解决方案

You can use onselect event to get dates.

$('#date1').datepicker({
   onSelect: function(dateText, inst) { 
       var d1=new Date(dateText);
       // get date from other text field
       var d2=new Date($('#date2').val());
       // d2 -d1 gives result in milliseconds
       // calculate number of days by Math.abs((d2-d1)/86400000, as 24*3600*1000 = 86400000
       // and populate it to some text field #textfield
       $('#textfield').val((Math.abs((d2-d1)/86400000)));
   }
}); 

这篇关于jQuery UI Datepicker - 日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆