[英]bootstrap-datetimepicker show date only
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). 我正在使用smalot的这个回购 ,我想只选择和显示日期(对于其他一些我显示数据和时间的地方,因此选择这个回购)。 I can manage to use it for selecting date only but the generated date string is always
yyyy-mm-dd hh:ii
. 我可以设法使用它来仅选择日期,但生成的日期字符串总是
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. 如果我不理解错误,
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 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
. 我将
startView
和minView
设置为2
这样用户只需要选择日期,但我仍然需要2015-09-22 00:00
作为输出 - 我只是想让它显示2015-09-22
。
In fact, by listening to changeDate
and hide events, I can just set the value of date inputs. 实际上,通过监听
changeDate
和隐藏事件,我只需设置日期输入的值即可。 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
);
Use date picker 使用日期选择器
$("#calender").datepicker({
format: "mm/dd/yyyy"
});
To show date only use 仅显示日期使用
format: 'L'
To show Time only use 显示时间仅使用
format: 'LT'
Reference 参考
https://github.com/Eonasdan/bootstrap-datetimepicker/issues/832
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! 希望可以帮到你!
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. 希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.