bootstrap-datetimepicker仅显示日期 [英] bootstrap-datetimepicker show date only
问题描述
我正在使用smalot的 repo ,我只选择并显示日期(对于其他一些地方,我正在显示数据和时间,因此请选择此仓库.我可以设法仅将其用于选择日期,但生成的日期字符串始终为yyyy-mm-dd hh:ii
.如果我不正确地理解format
选项,该选项仅用于解析初始日期,而不用于设置日期.
I am using this repo by 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 format
option is for parsing the initial date only but not setting dates.
<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>
我将startView
和minView
都设置为2
,以便用户只需要选择日期,但是我仍然得到2015-09-22 00:00
作为输出-我只希望它显示2015-09-22
I am setting startView
and minView
to be both 2
so that the user will need to select date only but I still got 2015-09-22 00:00
as the output-- I just want it to show 2015-09-22
.
实际上,通过监听changeDate
和隐藏事件,我可以设置日期输入的值.我想知道是否有一种更简单和肮脏的方式
In fact, by listening to changeDate
and 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
$('.datetimepicker').on('changeDate', function(e) {//get substring and set date input
}).on('hide'....//same thing
);
推荐答案
仅显示日期,请使用
format: 'L'
要仅显示时间,请使用
format: 'LT'
参考
https://github.com/Eonasdan/bootstrap-datetimepicker/issues/832
这篇关于bootstrap-datetimepicker仅显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!