Bootstrap 日期时间选择器步进不起作用
Bootstrap datetime picker stepping not working
我有一个带步进的日期时间选择器具有值 45.But 当我增加分钟数时,小时字段增加 1 小时。
$("#startDate").datetimepicker({ format:'YYYY/MM/DD HH:mm' , locale: g_state_language, useCurrent: false, stepping: 45, defaultDate: false, sideBySide:true });
12:00 到 12:45 有效,但 12:45 增加显示 01:45 而不是 01:30
datetimepicker
的 stepping
与舍入步骤一起使用。因此,为了解决您的问题,我在插件中添加了一个新选项,例如 forceMinuteStep
。
检查下面的示例,我如何同时使用 stepping
和 forceMinuteStep
来实现步长,而不管舍入值如何。
// Below changes I made in datetimepicker library.
setValue = function (targetMoment) {
...
...
// Only round if forceMinuteStep is not true otherwise use incremental value directly.
if (options.stepping !== 1 && !options.forceMinuteStep) {
var roundedMins = Math.round(targetMoment.minutes() / options.stepping) * options.stepping;
targetMoment.minutes((roundedMins) % 60).seconds(0);
targetMoment.minutes((Math.round(targetMoment.minutes() / options.stepping) * options.stepping) % 60).seconds(0);
}
...
}
我是如何使用 forceMinuteStep:true
启动插件的。
$('#datetimepicker1').datetimepicker({
defaultDate: moment('03/25/2018 08:45'),
stepping: 45,
forceMinuteStep: true
});
我有一个带步进的日期时间选择器具有值 45.But 当我增加分钟数时,小时字段增加 1 小时。
$("#startDate").datetimepicker({ format:'YYYY/MM/DD HH:mm' , locale: g_state_language, useCurrent: false, stepping: 45, defaultDate: false, sideBySide:true });
12:00 到 12:45 有效,但 12:45 增加显示 01:45 而不是 01:30
datetimepicker
的 stepping
与舍入步骤一起使用。因此,为了解决您的问题,我在插件中添加了一个新选项,例如 forceMinuteStep
。
检查下面的示例,我如何同时使用 stepping
和 forceMinuteStep
来实现步长,而不管舍入值如何。
// Below changes I made in datetimepicker library.
setValue = function (targetMoment) {
...
...
// Only round if forceMinuteStep is not true otherwise use incremental value directly.
if (options.stepping !== 1 && !options.forceMinuteStep) {
var roundedMins = Math.round(targetMoment.minutes() / options.stepping) * options.stepping;
targetMoment.minutes((roundedMins) % 60).seconds(0);
targetMoment.minutes((Math.round(targetMoment.minutes() / options.stepping) * options.stepping) % 60).seconds(0);
}
...
}
我是如何使用 forceMinuteStep:true
启动插件的。
$('#datetimepicker1').datetimepicker({
defaultDate: moment('03/25/2018 08:45'),
stepping: 45,
forceMinuteStep: true
});