简体   繁体   English

如何在 jQuery 中以 12 小时格式设置 datetimepicker

[英]how to set datetimepicker in 12 hours format in jQuery

My datetimepicker's dropdown is displaying the date in yyyy/mm/dd format and time in 12 hours format.我的 datetimepicker 的下拉菜单以yyyy/mm/dd格式显示日期,以 12 小时格式显示时间。 The problem is when I select a date and a time, the time gets displayed in 24 hours format.问题是当我选择日期和时间时,时间会以 24 小时格式显示。 Whereas I wanted the time to be displayed in 12 hours format.而我希望时间以 12 小时格式显示。

Here is my code:这是我的代码:

$('#datetimepicker').datetimepicker({
    dayOfWeekStart: 1,
    lang: 'en',
    formatTime: 'h:i a',            
    step: 05
});

I have figured this out.我已经想通了。 Kaushal Shah was close, but the output into the textbox was not showing in 12 hour format with his solution. Kaushal Shah 很接近,但他的解决方案没有以 12 小时格式显示到文本框中的输出。 You need to add the formatTime part as well as the format part, seen below.您需要添加 formatTime 部分以及格式部分,如下所示。

$('#datetimepicker').datetimepicker({
    dayOfWeekStart: 1,
    format: 'g:i a'
    lang: 'en',
    formatTime: 'g:i a',            
    step: 05
});

The solution I needed also contained more date information in the format section, so it looked more like this:我需要的解决方案还在格式部分包含更多日期信息,因此看起来更像这样:

$('#datetimepicker').datetimepicker({
    format: 'D M-d-Y g:i a',
    formatTime: 'g:i a',
    lang: 'en',
    step: 15
});

http://xdsoft.net/jqplugins/datetimepicker/ http://xdsoft.net/jqplugins/datetimepicker/

  • hours12: true小时12:是的

Should be a usefull link.应该是一个有用的链接。

Hope this helps you!希望这对你有帮助!

Correct Code is:正确的代码是:

$('#datetimepicker').datetimepicker({
    dayOfWeekStart: 1,
    lang: 'en',
    formatTime: 'g:i a',            
    step: 05
});

Or you can also try this: 'datetimepicker.CustomFormat = "HH:mm:ss tt";'或者你也可以试试这个:'datetimepicker.CustomFormat = "HH:mm:ss tt";'

Works!作品!

$('#datetimepicker').datetimepicker({
    formatTime: "hh:mm A",            
    step: 60
});

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

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