完美解决日期天数加减问题

1 篇文章 0 订阅
<span class="form_style">
      <label class="control-label">比对时间:</label>
      <div class="date datetimepicker" style="display:inline-block;padding:0;" id="startTime"
           data-date-format="yyyy-MM">
          <input class="form-control span2" name="startDate"
                 value="<#if requestReportLogSearchCondition??>${requestReportLogSearchCondition.startDate!''}</#if>"
                 id="startDate" type="text" required="true">
          <span class="add-on"><i class="icon-remove"></i></span>
          <span class="add-on"><i class="icon-th"></i></span>
      </div>
      <label><font color="red">*</font></label>
  </span>
  <span class="form_style" style="display: none">
      <label class="control-label">至:</label>
      <div class="date datetimepicker" style="display:inline-block;padding:0;" id="endTime"
           data-date-format="yyyy-MM-dd">
          <input class="form-control span2"
                 value="<#if requestLogSearchCondition??>${requestLogSearchCondition.endDate!''}</#if>"
                 name="endDate" id="endDate" type="text" required="true" disabled>
          <span class="add-on"><i class="icon-remove"></i></span>
          <span class="add-on"><i class="icon-th"></i></span>
      </div>
      <label><font color="red">*</font></label>
  </span>
<span class="form_style">
      <label class="control-label">至:</label>
      <div class="date datetimepicker" style="display:inline-block;padding:0;" id="endTimeVal1"
           data-date-format="yyyy-MM-dd">
          <input class="form-control span2"
                 value="<#if requestLogSearchCondition??>${requestLogSearchCondition.endDate!''}</#if>"
                 name="endTimeVal" id="endTimeVal" type="text" disabled>
          <span class="add-on"><i class="icon-remove"></i></span>
          <span class="add-on"><i class="icon-th"></i></span>
      </div>
      <label><font color="red">*</font></label>
  </span>



$("#startDate").change(function () {
    debugger;
    var startDate = $("#startDate").val();
    var curDate = new Date(startDate);
    var curMonth = curDate.getMonth();
    curDate.setMonth(curMonth + 1);
    curDate.setDate(0);
    var day = curDate.getDate();//当月天数

    var startTime = new Date(startDate);
    startTime = startTime.valueOf();
    startTime = startTime + day * 24 * 60 * 60 * 1000 - 1 * 24 * 60 * 60 * 1000;
    startTime = new Date(startTime);
    var now = "";
    /*+ "-" + startTime.getDate()*/
    now = startTime.getFullYear() + "-" + (startTime.getMonth() + 1);
    $("#endTimeVal").val(now);
})

$("#startDate").change(function () {
    debugger;
    var startDate = $("#startDate").val();
    var curDate = new Date(startDate);
    var curMonth = curDate.getMonth();
    curDate.setMonth(curMonth + 1);
    curDate.setDate(0);
    var day = curDate.getDate();//当月天数

    var startTime = new Date(startDate);
    startTime = startTime.valueOf();
    startTime = startTime + day * 24 * 60 * 60 * 1000;
    startTime = new Date(startTime);
    var now = "";
    /*+ "-" + startTime.getDate()*/
    now = startTime.getFullYear() + "-" + (startTime.getMonth() + 1);
    $("#endDate").val(now);
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值