简体   繁体   English

引导日期时间选择器删除子午线上午/下午

[英]Bootstrap datetime picker remove meridian am/pm

I'm using asp.net MVC TextBoxFor to bind bootstrap-datetimepicker. 我正在使用asp.net MVC TextBoxFor绑定bootstrap-datetimepicker。 It's working fine with simple input type text box. 简单的输入类型文本框可以正常工作。

But when I'm binding it with mvc textbox helper it's showing wrong year like '31/10/1899 00:00' 但是,当我使用mvc文本框助手将其绑定时,显示的年份不正确,例如“ '31/10/1899 00:00'

Then I got the solution somewhere to fix that. 然后我找到了解决该问题的解决方案。

$('.datetimepicker').datetimepicker({
    format: "dd-mm-yyyy hh:ii:00P",
    autoclose: true
});

It's working fine, but now It's adding meridians at the very end like AM/PM. 它工作正常,但现在它像AM / PM一样在最后添加了子午线。 I need to remove those AM/PM. 我需要删除那些AM / PM。 在此处输入图片说明

Any help would be appreciated. 任何帮助,将不胜感激。

只需删除foramt变量末尾的P,请参见下文

format: "dd-mm-yyyy hh:ii:00",

try this: 尝试这个:

$('.datetimepicker').datetimepicker({
            autoclose: true,
            showMeridian:false
        });

As two previous answers said, to remove meridian you can combine both format and showMeridian usage: 如前两个答案所述,要删除子午线,可以将formatshowMeridian用法结合使用:

$('.datetimepicker').datetimepicker({ 
    format: "dd-mm-yyyy hh:ii:00",
    autoclose: true,
    showMeridian: false
});

However, there is a glitch when datepicker lost its focus without selecting anything or making incomplete selections, it reverts date back to December 31, 1899 (reproduced in this example fiddle ). 但是,如果日期选择器在未选择任何内容或未进行完整选择的情况下失去了焦点,则会出现故障,它将日期恢复为1899年12月31日(在此示例中为小提琴 )。 I managed to check bootstrap-datetimepicker.js file and found parseDate function causing this behavior: 我设法检查bootstrap-datetimepicker.js文件,发现parseDate函数导致此行为:

parseDate: function (date, format, language, type, timezone) {
    var parts = date && date.toString().match(this.nonpunctuation) || [],
        // this line below represents December 31, 1899 (try using console.log)
        date = new Date(0, 0, 0, 0, 0, 0, 0), 
        // -- skipped for brevity --
    val, filtered, part;
    // -- skipped for brevity --
}

A little tweak is possible by changing date assignment into current date: 通过将date分配更改为当前日期可以进行一些调整:

parseDate: function (date, format, language, type, timezone) {
    var parts = date && date.toString().match(this.nonpunctuation) || [],
        date = new Date(),
        // -- skipped for brevity --
    val, filtered, part;
    // -- skipped for brevity --
}

Note: This tweak only available for non-CDN script (installed through NuGet package or manually placed in Scripts folder). 注意:此调整仅适用于非CDN脚本(通过NuGet软件包安装或手动放置在Scripts文件夹中)。

Related issues: 相关问题:

Issue #494: Date set to '31 Dec 1899 00:00' when focus lost without selecting date 问题#494:如果焦点丢失而没有选择日期,则日期设置为“ 1899年12月31日00:00”

Issue #153 第153期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM