Javascript jQuery DatePicker 设置时间和日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12787569/
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
jQuery DatePicker set time and date
提问by Doc Holiday
Hello I was asked to modify some code. We got something like this:
你好,我被要求修改一些代码。我们得到了这样的东西:
$("#expiration_datepicker").datetimepicker( "option", "disabled", false ).attr('value', '');
$("#expiration_datepicker").datetimepicker(
{
dateFormat: 'mm-dd-yy',
showOn: 'button',
buttonImage: '../chassis/images/calendar.gif',
buttonImageOnly: true,
minDate: 0,
maxDate: '+5Y',
duration: '',
<c:if test="${formIsReadonly or form.newsItemId == '-1'}">disabled: true,</c:if>
constrainInput: false,
timeFormat: 'hh:mm'
});
Looks like this is setting up the date picker
看起来这是设置日期选择器
How Can I set it up to default show todays date and time?? like dd-m-yy hh:mm
如何将其设置为默认显示今天的日期和时间?喜欢 dd-m-yy hh:mm
回答by ?????
回答by ?????
Check the datepickers documentation for more customizations. Surely it have..
查看日期选择器文档以获取更多自定义。肯定有..
$("#expiration_datepicker").datetimepicker( "option", "disabled", false ).attr('value', '');
$("#expiration_datepicker").datetimepicker(
{
**dateFormat: 'dd-m-yy',** // date format goes here
showOn: 'button',
buttonImage: '../chassis/images/calendar.gif',
buttonImageOnly: true,
minDate: 0,
maxDate: '+5Y',
duration: '',
<c:if test="${formIsReadonly or form.newsItemId == '-1'}">disabled: true,</c:if>
constrainInput: false,
timeFormat: 'hh:mm' // time format here
});
Usage :
用法 :
<script>
$('#expiration_datepicker').click(function(){
('#expiration_datepicker').datetimepicker('setDate', (new Date()) );
});
</script>
回答by Bhushan Kawadkar
need to add '.datepicker("setDate", "0")' after datetimepicker call. see the code below.
需要在 datetimepicker 调用后添加 '.datepicker("setDate", "0")'。请参阅下面的代码。
$("#expiration_datepicker").datetimepicker( "option", "disabled", false ).attr('value', '');
$("#expiration_datepicker").datetimepicker( {
dateFormat: 'dd-m-yy hh:mm', // format goes here. Check its documentation for more.
showOn: 'button',
buttonImage: '../chassis/images/calendar.gif',
buttonImageOnly: true,
minDate: 0,
maxDate: '+5Y',
duration: '',
<c:if test="${formIsReadonly or form.newsItemId == '-1'}">disabled: true,</c:if> constrainInput: false,
timeFormat: 'hh:mm' }).datetimepicker("setDate", "0");
回答by adio
set date programatically
以编程方式设置日期
$('#inputID').datetimepicker("setDate", "05.01.2017 13:36");