jQuery DateTimePicker 时间选择器在 24 小时内显示但在 12 小时内显示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21847443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DateTimePicker time picker in 24 hour but displaying in 12hr?
提问by RegDHunter
I'm using the bootstrap ready date time picker from http://eonasdan.github.io/bootstrap-datetimepicker/and it's working nicely but for one issue. I have a picker setup just from time as so:
我正在使用来自http://eonasdan.github.io/bootstrap-datetimepicker/的引导程序就绪日期时间选择器,它运行良好,但有一个问题。我刚好有一个选择器设置:
$(function () {
$('#startTime, #endTime').datetimepicker({
format: 'hh:mm',
pickDate: false,
pickSeconds: false,
pick12HourFormat: false
});
});
This sets the picker to 24 hour so I can select 19:00 as a time. But when I choose this time it displays as 07:00 in the input box. Here is the setup displaying the picker:
这将选择器设置为 24 小时,因此我可以选择 19:00 作为时间。但是当我选择这个时间时,它在输入框中显示为 07:00。这是显示选择器的设置:
<div class="input-group date timePicker" id="endTime">
<input type='text' class="form-control" readonly="true"
id="endTimeContent" /> <span class="input-group-addon"><span
class="glyphicon glyphicon-time"></span> </span>
</div>
Is there a specific data-format I can use for 24 hour in the input box?
我可以在输入框中使用 24 小时的特定数据格式吗?
回答by Benjam
Because the picker script is using moment.jsto parse the format string, you can read the docs there for proper format strings.
因为选择器脚本使用moment.js来解析格式字符串,所以您可以阅读那里的文档以获取正确的格式字符串。
But for 24Hr time, use HH
instead of hh
in the format.
但是对于 24Hr 时间,使用HH
而不是hh
在格式中。
$(function () {
$('#startTime, #endTime').datetimepicker({
format: 'HH:mm',
pickDate: false,
pickSeconds: false,
pick12HourFormat: false
});
});
回答by Piccin
To show the correct 24H format, for example, only put
例如,要显示正确的 24H 格式,只需输入
$(function () {
$('#date').datetimepicker({
format: 'DD/MM/YYYY HH:mm',
});
});
回答by Karthick Kumar
$(function () {
$('#startTime, #endTimeContent').datetimepicker({
format: 'HH:mm',
pickDate: false,
pickSeconds: false,
pick12HourFormat: false
});
});
your selector seems to be wrong,please check it
您的选择器似乎有误,请检查
回答by Gustavo Mi?o
Just this!
只是这个!
$(function () {
$('#date').datetimepicker({
format: 'H:m',
});
});
i use v4 and work well!!
我使用 v4 并且运行良好!!
回答by qakmak
I don't understand why the other friends tell you use HH
, But after I test so many time, The correct 24 hour format is :
我不明白为什么其他朋友告诉你使用HH
,但我测试了这么多次后,正确的24小时格式是:
hh
呵呵
.
.
I see it from : http://www.malot.fr/bootstrap-datetimepicker/
我看到它来自:http: //www.malot.fr/bootstrap-datetimepicker/
I don't know why they don't use the common type HH
for 24 hour.....
我不知道为什么他们不使用普通类型HH
24 小时.....
I hope anyone could tell me if I'm wrong.....
如果我错了,希望有人能告诉我......
回答by Pranesh Janarthanan
With seconds!
秒!
$('.Timestamp').datetimepicker({
format: 'DD/MM/YYYY HH:mm:ss'
});
To skip future dates:
跳过未来的日期:
$(function () {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datetimepicker,#datetimepicker1').datetimepicker({
pickTime: false,
format: "DD-MM-YYYY",
maxDate: new Date(currentYear, currentMonth, currentDate + 1)
});
});
回答by Aaska Patel
Meridian pertains to AM/PM, by setting it to false you're indicating you don't want AM/PM, therefore you want 24-hour clock implicitly.
Meridian 与 AM/PM 相关,通过将其设置为 false,您表示您不想要 AM/PM,因此您隐含地想要 24 小时制。
$('#timepicker1').timepicker({showMeridian:false});
回答by Sagar Nair
I know it's been quite some time since the question was asked. However, if it helps anyone this worked for me.
我知道自从提出这个问题以来已经有一段时间了。但是,如果它可以帮助任何人,这对我有用。
$(function() {
$('.datetimepicker').datetimepicker({
format: 'MM-DD-YYYY HH:mm '
});
});
回答by Jegan
'DD/MM/YYYY hh:mm A' => 12 hours 'DD/MM/YYYY HH:mm A' => 24 hours
'DD/MM/YYYY hh:mm A' => 12 小时 'DD/MM/YYYY HH:mm A' => 24 小时
回答by Tayyab Hayat
this will display current ate & time. Working on my side perfectly
这将显示当前的饮食和时间。完美地在我身边工作
$("#datePicker").datetimepicker({
format: 'DD-MM-YYYY HH:mm A',
defaultDate: new Date(),
});