【问题标题】:How do I convert this date range (month,year) date picker to show the output of the month in numeric format如何转换此日期范围(月,年)日期选择器以数字格式显示月份的输出
【发布时间】:2016-01-16 17:42:35
【问题描述】:
 $( "#SAProstarteDate, #SAProendDate" ).datepicker({ 
     changeMonth: true,
     changeYear: true,
     showButtonPanel: true,
     dateFormat: 'MMyy',            
     onClose: function(dateText, inst) { 
          var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
          var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();             
          $(this).datepicker('setDate', new Date(year, month, 1));
     },
     beforeShow : function(input, inst) {
         if ((datestr = $(this).val()).length > 0) {
             year = datestr.substring(datestr.length-4, datestr.length);
             month = jQuery.inArray(datestr.substring(0, datestr.length-5), $(this).datepicker('option', 'monthNames'));
             $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
             $(this).datepicker('setDate', new Date(year, month, 1));    
         }
         var other = this.id == "SAProstarteDate" ? "#SAProendDate" : "#SAProstarteDate";
         var option = this.id == "SAProstarteDate" ? "maxDate" : "minDate";        
         if ((selectedDate = $(other).val()).length > 0) {
             year = selectedDate.substring(selectedDate.length-4, selectedDate.length);
             month = jQuery.inArray(selectedDate.substring(0, selectedDate.length-5), $(this).datepicker('option', 'monthNames'));
             $(this).datepicker( "option", option, new Date(year, month, 1));
         }
     }
 });


----------
<div class="col-lg-4 col-md-4">                                                                        
    <div class="form-horizontal">
        <div class="form-group">
            <label for="SAProstarteDate" class="col-sm-4 control-label">Start Date</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" validate="true" match="^(19|20)\d\d[- ](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$"  error="* Please enter a valid Dispatch Date" id="SAProstarteDate" name="SAProstarteDate" placeholder="YYYY-MM" readonly="readonly">
                <div class="text-danger error" role="alert">This is the error msg!</div>
            </div>
        </div>
    </div>                                                                          
</div>
<div class="col-lg-4 col-md-4">                                                                        
    <div class="form-horizontal">
        <div class="form-group">
            <label for="SAProendDate" class="col-sm-4 control-label">End Date</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" validate="true" match="^(19|20)\d\d[- ](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$"  error="* Please enter a valid Dispatch Date" id="SAProendDate" name="SAProendDate" placeholder="YYYY-MM" readonly="readonly">
                <div class="text-danger error" role="alert">This is the error msg!</div>
            </div>
        </div>
    </div>                                                                          
</div>

如何转换此日期范围(月、年)日期选择器以以数字格式显示月份的输出 - 月份和日期应为数字格式 (mmyy) 请帮助将其转换为该格式

【问题讨论】:

  • 欢迎来到 Stack Overflow!当您提出问题时,文本区域右侧有一个橙色的大如何格式化框,其中包含有用的信息。还有一个完整的格式化辅助工具栏。还有一个 [?] 按钮提供格式化帮助。 一个预览区域,位于文本区域和发布您的问题按钮(以便您必须扫描过去才能找到该按钮)之间,显示您的帖子发布后的样子。使您的帖子清晰,并证明您花时间这样做,可以提高您获得好答案的机会。
  • 另外,请使用tour,环顾四周,并通读help center,尤其是How do I ask a good question? 这个问题太宽泛了。你试过什么?你卡在哪一部分了?

标签: javascript jquery jquery-ui jquery-plugins datepicker


【解决方案1】:

你好我刚刚解决了这个问题,把步骤放在下面的链接里:After changing the date format in jquery month picker, why the from<to function not works anymore.

请注意 substr 函数,因为我在这方面犯了错误。

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    相关资源
    最近更新 更多