JQuery datepicker - 选择一个月的最后一天 [英] JQuery datepicker - Selecting the last day of the month

查看:1133
本文介绍了JQuery datepicker - 选择一个月的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在报表生成器中,我写了用户可以选择日期范围来显示结果。但是,由于本报告的数据是每月生成的,因此日期范围的日期部分真的是无关紧要的。我现在有要求将所选开始日期的日期更改为1,而不管用户选择什么。我已经这样做了:

In a report generator I wrote the user can select a date range to display results for. But since the data for this report is generated monthly the day portion of the date range is really irrelevant. I now have the requirement to change the day of the selected start date to '1' regardless of what the user has selected. I've done this like so:

$('#TextStartDate').datepicker({ maxDate: "+0M", minDate: "-24M", dateFormat: 'm/1/yy' });

要求的第二个栏目是选择的结束日期的日期设置为最后一天无论选择了哪一天。因此,如果用户选择结束日期为5/16/2011,则日期字段将显示5/31/2011。这是我被卡住的地方。

The second pard of the requirement is that the day of the selected end date be set to the last day of the month regardless of what day was selected. So if the user selected an end date of 5/16/2011 then the date field would show 5/31/2011. This is where I get stuck.

任何帮助将不胜感激。

推荐答案

我发现的技巧是:


  1. 在选择日添加一个月

  2. 回合该月的第一天

  3. 减去1天。

  1. Add one month to the select day
  2. Round to the first day of that month
  3. Subtract 1 day.

不一定很漂亮,但它可以工作。 >

Not necessarily pretty, but it works.

计划B:


  1. 圆选择一个月的第一个月

  2. 添加1个月

  3. 减去1天

注意:使用快速示例代码将稍后添加

这篇关于JQuery datepicker - 选择一个月的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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