【问题标题】:Return last day of last month when using Bootstrap Datepicker to select month使用 Bootstrap Datepicker 选择月份时返回上个月的最后一天
【发布时间】:2016-04-29 17:41:12
【问题描述】:

我想用Bootstrap datepicker只选择月份,但它总是返回上个月的最后一天,例如,如果我选择2016年1月,它返回12-31-2015,我想得到第一天我选择的月份。

我的代码:

if ($(this).hasClass('month-only')) {
      $(this).prop('readonly', true).datepicker({
        format: 'yyyy-mm',
        viewMode: 'months',
        minViewMode: 'months',
        autoclose: true
      });
    }

【问题讨论】:

    标签: jquery twitter-bootstrap bootstrap-datepicker


    【解决方案1】:

    嗯,上面的答案没有在 jsfiddle 链接中将日期设置为月底。如果有人仍在寻找答案,我在此帖子中提供了更新的答案:bootstap Datepicker : set value as last day of the month not working

    您需要使用 'changeDate' 事件和 'update' 方法来设置日期,以避免默认的每月第一天。

    【讨论】:

      【解决方案2】:
      $('#input').datepicker({
          minViewMode: 1,
          format: 'yyyy-mm-dd',
          autoclose: true
      });
      

      应该可以https://jsfiddle.net/z56j2eod/3/

      或者如果你只想要 yyyy-mm 你的代码就可以工作 https://jsfiddle.net/z56j2eod/4/

      【讨论】:

        【解决方案3】:

        $(".of-date").persianDatepicker({ 内联:假, altField: '#ofDate', altFormat: 'YYYY/MM/DD', 日期选择器:{ 启用:假 } });

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-24
          • 2013-10-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多