jQuery UI Datepicker差异天数 [英] jQuery UI Datepicker difference in days

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

问题描述

我需要计算所选日期和当前日期之间的差异周数。我试图用 weekNumberPicked - weekNumberCurrent 计算,但如果两个日期在不同的年份,结果是不正确的,所以我可能需要像 daysDifference / 7 。如何使用 onSelect 操作来实现?

解决方案

您可以使用Datepicker的函数getDate获取Date对象。



然后从另一个减去一个日期(也许想要获得绝对值)以获得差异的毫秒,并计算差异以天或星期计算。


$ b $ ($ {
onSelect:function(){
var date = $(this).datepicker('getDate ');
var today = new Date();
var dayDiff = Math.ceil((今天 - 日期)/(1000 * 60 * 60 * 24));
}
});


I need to calculate the number of weeks difference between the chosen date and the current date. I've tried to calculate with weekNumberPicked - weekNumberCurrent, but if the two dates are in different years, the result is incorrect, so I probably need to get it like daysDifference / 7. How should I implement this with the onSelect action?

解决方案

You can use the Datepicker's function getDate to get a Date object.

Then just subtract one date from the other (might want to get the absolute value as well) to get the milliseconds in difference, and calculate the difference in days, or weeks.

$('#test').datepicker({
    onSelect: function() {
        var date = $(this).datepicker('getDate');
        var today = new Date();
        var dayDiff = Math.ceil((today - date) / (1000 * 60 * 60 * 24));
    }
});

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

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