twitter-bootstrap bootstrap-datetimepicker 仅显示日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34525664/
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
bootstrap-datetimepicker show date only
提问by Junchao Gu
I am using this repoby smalot and I want to select and show date only (for some other places I am showing data and time, therefore selecting this repo). I can manage to use it for selecting date only but the generated date string is always yyyy-mm-dd hh:ii. And if I did not understand wrongly the formatoption is for parsing the initial date only but not setting dates.
我正在通过 smalot使用这个repo,我只想选择和显示日期(对于其他一些地方,我显示数据和时间,因此选择了这个 repo)。我可以设法将它仅用于选择日期,但生成的日期字符串始终为yyyy-mm-dd hh:ii. 如果我没有理解错误,该format选项是仅解析初始日期而不是设置日期。
<div class="input-group date datetime dateonly" data-start-view="2" data-min-view="2" style="margin-bottom: 0;">
<input class="form-control" size="16" type="text" placeholder="Release Date" id="release-date" name="release_date" value="{{ unit.release_dt|date:'Y-m-d' }}" style="cursor: default; background-color: #ffffff;">
<span class="input-group-addon btn btn-primary"><span class="glyphicon glyphicon-th"></span></span>
</div>
I am setting startViewand minViewto be both 2so that the user will need to select date only but I still got 2015-09-22 00:00as the output-- I just want it to show 2015-09-22.
我正在设置startView和设置minView两者,2以便用户只需要选择日期,但我仍然2015-09-22 00:00作为输出 - 我只是想让它显示2015-09-22.
In fact, by listening to changeDateand hide events, I can just set the value of date inputs. I am wondering if there is a less hacky and dirty way of doing it
事实上,通过监听changeDate和隐藏事件,我可以只设置日期输入的值。我想知道是否有一种不那么肮脏和肮脏的方式来做到这一点
$('.datetimepicker').on('changeDate', function(e) {//get substring and set date input
}).on('hide'....//same thing
);
回答by Pankaj Mandale
Use date picker
使用日期选择器
$("#calender").datepicker({
format: "mm/dd/yyyy"
});
回答by saad
To show date only use
仅显示日期使用
format: 'L'
To show Time only use
只显示时间使用
format: 'LT'
Reference
参考
https://github.com/Eonasdan/bootstrap-datetimepicker/issues/832
回答by u5729830
you will edit datetaimepicker.js
您将编辑 datetaimepicker.js
var defaults = $.fn.datepicker.defaults = {
autoclose: false,
beforeShowDay: $.noop,
calendarWeeks: false,
clearBtn: false,
daysOfWeekDisabled: [],
endDate: Infinity,
forceParse: true,
//format: 'mm/dd/yyyy', 时间输出格式
format: 'yyyy-mm-dd',
keyboardNavigation: true,
language: 'en',
minViewMode: 0,
multidate: false,
multidateSeparator: ',',
orientation: "auto",
rtl: false,
startDate: -Infinity,
startView: 0,
todayBtn: false,
todayHighlight: false,
weekStart: 0
};
like this
像这样
//format: 'mm/dd/yyyy', 时间输出格式
format: 'yyyy-mm-dd'
wish can help you!
希望能帮到你!
回答by Maddy
Try this - HTML:
试试这个 - HTML:
<div class="controls input-append date m" data-date="" data-date-format="yyyy-mm-dd" data-link-field="m1" data-link-format="yyyy-mm-dd" data-start-view="2" data-min-view="2">
<input size="16" id="m" type="text" value="" readonly>
<span class="add-on"><i class="icon-remove"></i></span>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<input type="hidden" id="m1" value="" />
JS:
JS:
$('.m').on('changeDate', function(e) {
console.log($("#m").val());
});
Console:
安慰:
2015-12-08
Hope it will help.
希望它会有所帮助。

