jQuery 如何在jquery datepicker中只显示时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16862897/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:55:47  来源:igfitidea点击:

how to display only time in jquery datepicker?

jquery

提问by open source guy

I want to display only time from jquery datepicker. my current code is

我只想显示来自 jquery datepicker 的时间。我目前的代码是

$('#field-start_t_a').datetimepicker({
  showDate:false, 
   showSecond: true,

   timeFormat: 'hh:mm'
});

current output is

当前输出是

05/31/2013 00:12

required output is

所需的输出是

00:12

回答by prograhammer

Just set dateFormat to an empty string dateFormat: ''

只需将 dateFormat 设置为空字符串 dateFormat: ''

$('#field-start_t_a').datetimepicker({
    dateFormat: '',
    timeFormat: 'hh:mm tt'
});

(this is a little strange that you only want to set time from the datetimepicker, because you can also do $('#field-start_t_a').timepicker();and only the time options show)

(这有点奇怪,您只想从 datetimepicker 设置时间,因为您也可以这样做$('#field-start_t_a').timepicker();并且只显示时间选项)

回答by adam

try a code like this:

试试这样的代码:

<script>
  $('#time_input').datetimepicker({
     datepicker:false,
      format:'H:i'
  }); 
</script>

回答by cmd

$('.picker').datetimepicker({
    dateFormat: '',
        timeFormat: 'hh:mm tt',
        **timeOnly: true**
});

回答by Nuno Prata

Just adding a simple solution. By adding only this , you can get a time only date picker

只需添加一个简单的解决方案。通过只添加这个,你可以获得一个仅限时间的日期选择器

$('YOUR_SELECTOR').datetimepicker({
        format: "HH:mm"
});

Simple solution, hope it helps.

简单的解决方法,希望有帮助。

回答by Vineesh Kalarickal

<script type="text/javascript">                                   

$("#time_field_id").datetimepicker({                   
dateFormat: '', 
timeFormat: 'hh:mm tt', 
timeOnly: true                                   
 }); 

</script>

回答by mr kaveh

$(function () {
   $('#datetimepicker').datetimepicker({
        format:'H:i:s',
        inline: true,
        sideBySide: true
   })
});

try this .worked for me

试试这个。对我有用

回答by muhibun syairoji

Try this, works like a charm !

试试这个,就像一个魅力!

$('.time_only').datetimepicker({
    pickDate : false ,
    format: 'hh:mm' 
});