如何在 JQuery Datetimepicker 插件中只显示日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19909614/
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
How to show only date in JQuery Datetimepicker addon?
提问by Robert Persson
I've searched high and low for an answer to my question but haven't found one, I did find two related questions though: JQuery Datepicker should display date only, jQuery UI DateTimepicker - cannot hide the time
我已经搜索了很多关于我的问题的答案,但没有找到,但我确实找到了两个相关的问题:JQuery Datepicker should display date only, jQuery UI DateTimepicker - cannot hide the time
But they didn't solve my problem.
但是他们没有解决我的问题。
I'm using Trent Richardsons datetimepicker and I would like it to show only date in the textbox. The answer to why I'm not using the datepicker without the addon is because sometimes I want it to show datetime and sometimes only date.
我正在使用 Trent Richardsons datetimepicker,我希望它在文本框中只显示日期。为什么我不使用没有插件的日期选择器的答案是因为有时我希望它显示日期时间,有时只显示日期。
I've can hide the timepicker with the following code:
我可以使用以下代码隐藏时间选择器:
datetimepicker("option", "showTimepicker", false);
The time disappears from my textbox but the date has a trailing space, "2013-11-01 " I've tried the option for separator but no luck.
时间从我的文本框中消失,但日期有一个尾随空格,“2013-11-01”我已经尝试了分隔符的选项,但没有运气。
datetimepicker("option", "separator", "");
Anyone got an idea how I can solve this?
任何人都知道我该如何解决这个问题?
A bit clarification, I'm trying to write kind of a component that can be used through a large solution where it sometimes needs to be a datetimepicker and sometimes a datepicker. This "component" contains an input (my datetimepicker) that is wrapped in some html. It also has properties that can be set, one of them is the SetDateOnly(), and that is where I'm trying to get the datepicker to show only date.
稍微澄清一下,我正在尝试编写一种可以通过大型解决方案使用的组件,它有时需要是日期时间选择器,有时需要是日期选择器。这个“组件”包含一个包含在一些 html 中的输入(我的日期时间选择器)。它还具有可以设置的属性,其中之一是 SetDateOnly(),这就是我试图让日期选择器仅显示日期的地方。
回答by Ibanêz
Try this options:
试试这个选项:
$("#selector").datetimepicker({
minView: 2,
format: 'YYYY-MM-DD'
});
回答by GDG
Then you can go with showTimePickerlike this:-
然后你可以像这样使用showTimePicker:-
On Form Load
在表单加载时
$(document).ready(function(){
$('#selector').datetimepicker({
'showTimepicker': false
});
});
On run time
在运行时
$(".btn").click(function(){
$('#selector').datetimepicker("destroy"); //destroys the previous settings.
$('#selector').datetimepicker({
'showTimepicker': false
});
});
回答by Corrot
$(document).ready(function(){
$('#selector').datetimepicker({
viewMode: 'days',
format: 'DD/MM/YYYY'
});
});
It works like this.
它是这样工作的。
回答by GDG
Why not like this:
为什么不喜欢这个:
$('#selector').datetimepicker(); // When required both functionalities.
$('#selector').timepicker(); // When only time is required.
$('#selector').datepicker(); // Otherwise regular datepicker can be used.
回答by Ashish Thakur
This is working for me :)
这对我有用:)
$("#selector").datetimepicker({
minView: 2,
format: 'dd-mm-yyyy',
autoclose: true
});
回答by sandeep kumar
if another code not work then you can use this code
如果另一个代码不起作用,那么您可以使用此代码
$('#datetimepicker_date_to_view').datetimepicker({
timepicker:false,
format:'d.m.Y',
}).on('change', function() {
$('.xdsoft_datetimepicker').hide();
var str = $(this).val();
str = str.split(".");
$('#alt_date_field').val(str[2]+'-'+str[1]+'-'+str[0]);
});
回答by Gabriel Reguly
This is my solution:
这是我的解决方案:
$("#Time").datetimepicker({
datepicker: false,
step: 15,
format: 'g:i a',
});
Using jQuery DateTimePicker plugin v2.3.8
使用 jQuery DateTimePicker 插件 v2.3.8
回答by willer2k
As per the documentation it is:
根据文档,它是:
$("#selector").datetimepicker({
format: 'L'
});
回答by ANIL PATEL
I tried this. It's working for me. The following format parameter has to set under the datetimepicker like this 'YYYY-MM-DD'
我试过这个。它对我有用。以下格式参数必须在 datetimepicker 下设置,如“YYYY-MM-DD”
$(document).ready(function(){
$('#selector').datetimepicker({
format: 'YYYY-MM-DD'
});
});`
回答by ANIL PATEL
<script type="text/javascript">
$(function () {
$('#selector').datetimepicker({
format: 'YYYY-MM-DD'
});
});
</script>