jquery datepicker,日期范围计数

发布于 2024-08-18 17:12:04 字数 565 浏览 9 评论 0原文

我正在尝试使用 jquery datepicker 来总结或扣除选定范围内的日期,这就是我现在正在做的事情,但没有任何运气。

function test(){
    var sundayCheck = 0;
    var saturdayCheck = 0;
    var totalDays = 0;

    sundayCheck = new Date($("#onlySunday").datepicker("getDate"));
    saturdayCheck = new Date($("#onlySaturday").datepicker("getDate"));

    totalDays = saturdayCheck.getDate() - sundayCheck.getDate();

    alert(totalDays);
}

这是一段应该进行计算的代码,但它所做的只是扣除天数,例如

24.01.10 - 06.02.10 = -18,这是完全错误的,因为它应该更多天数,它只是不考虑天数并且只是使用日期的第一个数字。

如果有人可以帮助如何进行此类计算,我将不胜感激。

i am trying to sum up or deduct dates in selected range using jquery datepicker, here is how i am doing it right now but without any luck.

function test(){
    var sundayCheck = 0;
    var saturdayCheck = 0;
    var totalDays = 0;

    sundayCheck = new Date($("#onlySunday").datepicker("getDate"));
    saturdayCheck = new Date($("#onlySaturday").datepicker("getDate"));

    totalDays = saturdayCheck.getDate() - sundayCheck.getDate();

    alert(totalDays);
}

thats a piece of code that should make calculation but what it does is just deducts days like,

24.01.10 - 06.02.10 = -18 which is totaly wrong as it should be more days its just does not consider the days and its just using first numbers of dates.

If anyone could help how to make such calculations i would appreciate the most.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-08-25 17:12:04

您是否想确定两个日期之间的天数?

  totalDays = Math.ceil((saturdayCheck.getTime()-sundayCheck.getTime())/(1000*60*60*24);

首先获取两个日期之间的毫秒数,然后除以一天中的毫秒数。使用 Math.ceil 向上舍入到最接近的整数。

Are you trying to dtermine the number of days between two dates?

  totalDays = Math.ceil((saturdayCheck.getTime()-sundayCheck.getTime())/(1000*60*60*24);

First get the number of milliseconds between the two dates then divide by the number of milliseconds in a day. Using Math.ceil to round up to nearest integer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文