我有一个带步进值 45 的日期时间选择器。但是当我增加分钟数时,小时字段会增加 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
来实现 step,而不考虑舍入值。
// 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
});
关于javascript - Bootstrap 日期时间选择器步进不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49484669/