【问题标题】:Bootstrap datetime picker stepping not working引导日期时间选择器步进不起作用
【发布时间】:2018-09-04 04:43:40
【问题描述】:

我有一个带步进的日期时间选择器,其值为 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

【问题讨论】:

标签: javascript jquery bootstrap-4 datetimepicker


【解决方案1】:

datetimepickerstepping 使用舍入步骤。因此,为了解决您的问题,我在插件中添加了一个新选项,例如 forceMinuteStep

Sample fiddle

查看下面的示例,我如何同时使用steppingforceMinuteStep 来实现步长,而不考虑舍入值。

// 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
});

【讨论】:

    猜你喜欢
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    相关资源
    最近更新 更多