DateRangePicker(http://www.daterangepicker.com/)创建错误的值。例如,当我选择值13:00时,它在输入中显示为01:00
我已将timePicker24Hour
设置为true,所以我真的不知道是什么问题
网页代码
$(function() {
$('input[class*="datetimes"]').daterangepicker({
autoUpdateInput: true,
singleDatePicker: true,
timePicker: true,
minYear: 1901,
timePicker24Hour: true,
timePickerIncrement: 5,
maxYear: parseInt(moment().format('YYYY'), 10),
locale: {
format: 'YYYY-MM-DD hh:mm'
},
opens: "center"
});
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<input class="form-control datetimes" type="text" name="end_time" id="end_time" />
有人有这个错误吗?或者我配置错了?
答案 0 :(得分:1)
您需要大写的HH
(24h格式)为日期格式
$(function() {
$('input[class*="datetimes"]').daterangepicker({
autoUpdateInput: true,
singleDatePicker: true,
timePicker: true,
minYear: 1901,
timePicker24Hour: true,
timePickerIncrement: 5,
maxYear: parseInt(moment().format('YYYY'),10),
locale: {
format: 'YYYY-MM-DD HH:mm'
},
opens: "center"
});
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<input class="form-control datetimes" type="text" name="end_time" id="end_time" />
答案 1 :(得分:1)
您的问题是,您要输出回输入(通过语言环境)的格式为hh:mm
,即12小时格式(mm
)。您想改用HH
,将整个格式设为YYYY-MM-DD HH:mm
。通过像以前一样执行timePicker24Hour: true
,日期选择器本身被设置为24小时格式。
$(function() {
$('input[class*="datetimes"]').daterangepicker({
autoUpdateInput: true,
singleDatePicker: true,
timePicker: true,
minYear: 1901,
timePicker24Hour: true,
timePickerIncrement: 5,
maxYear: parseInt(moment().format('YYYY'),10),
locale: {
format: 'YYYY-MM-DD HH:mm'
},
opens: "center"
});
});
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<input class="form-control datetimes" type="text" name="end_time" id="end_time" />