twitter-bootstrap Eonasdan Bootstrap 日期时间选择器格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29385192/
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
Eonasdan Bootstrap datetimepicker format
提问by sathish kumar
How to set a format in bootstrap 3 datetimepicker. I want the format "dd/MM/yyyy hh:mm" and I dont want "AM" and "PM". For that in which language I can use here. The following fiddle How can I do this?
如何在 bootstrap 3 datetimepicker 中设置格式。我想要格式“dd/MM/yyyy hh:mm”,我不想要“AM”和“PM”。对于我可以在这里使用的语言。下面的小提琴我该怎么做?
http://jsfiddle.net/Eonasdan/0Ltv25o8/
http://jsfiddle.net/Eonasdan/0Ltv25o8/
$('#datetimepicker1').datetimepicker({
format : "dd/MM/yyyy hh:mm",
});
<!-- padding for jsfiddle -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" /> <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
</div>
</div>
</div>
</div>
回答by br3w5
$('#datetimepicker1').datetimepicker({format : "DD/MM/YYYY hh:mm"});
$('#datetimepicker2').datetimepicker({format : "DD/MM/YYYY hh:mm"});
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
</head>
<br/>
<!-- padding for jsfiddle -->
<div class="row">
<div class="col-md-12">
<h6>datetimepicker1</h6>
<div class="form-group">
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" /> <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
</div>
</div>
<h6>datetimepicker2</h6>
<input type="text" class="form-control" id="datetimepicker2" />
</div>
</div>
I'm not sure why yours isn't working, using dd/MM/yyyy hh:mmgives the output We/04/yyyy 08:43. If you want the output to be for example 01/03/2015 12:01you need to set format : "DD/MM/YYYY hh:mm". For more information on format options take a look at the momentjsdocumentation.
我不确定为什么你的不起作用, usingdd/MM/yyyy hh:mm给出了 output We/04/yyyy 08:43。例如,如果您希望输出为,则01/03/2015 12:01需要设置format : "DD/MM/YYYY hh:mm". 有关格式选项的更多信息,请查看momentjs文档。
See updated jsfiddle
查看更新的jsfiddle
You need to make sure that you include all of the necessary css and js files that the datetimepicker needs to work. You also need momentjs and jquery to load first. See code snippet.
您需要确保包含 datetimepicker 需要工作的所有必要 css 和 js 文件。您还需要首先加载 momentjs 和 jquery。请参阅代码片段。
回答by SuperNova
adding data-date-format="YYYY-MM-DD HH:mm" in the input tag also works.
在输入标签中添加 data-date-format="YYYY-MM-DD HH:mm" 也有效。
<input type="text" class="form-control" data-date-format="YYYY-MM-DD HH:mm"/>

