$( "#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)Plz帮助将其转换为该格式
答案 0 :(得分:1)
您好我刚刚解决了这个问题,并将步骤放在以下链接中:After changing the date format in jquery month picker, why the from<to function not works anymore。
请注意substr函数,因为我犯了错误。