Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wan't datetimepicker to show only rounded hours and disable minutes selection. So user will be able to pick only hours, like 02:00. However I can't achieve this simple task. Here is my code (in a Laravel view):

$("#date_from").datetimepicker({
    format: 'yyyy-mm-dd hh:00',
    startDate: "{{date('Y-m-d')}}",
    minuteStepping: 60,
    autoclose: true }).on('hide', function(e) {
        $("#date_to").datetimepicker(
            "setStartDate", new Date($('#date_from').val())
         )....

I've tried steps: 60, stepping:60, minView: 1 and others. Still I'm getting this enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
294 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here is one example for you, i think it will help you.

jsfiddle.net/tmk0293z/7/

There is changedate event bind with a function and changes the another startdate of other field.

Thanks, Nishit Zinzuvadiya

Here is the actual code (HTML):

<div class="input-append date form_datetime" id="first">
<input type="text" value="" readonly>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<div class="input-append date form_datetime" id="second">
    <input type="text" value="" readonly>
    <span class="add-on"><i class="icon-th"></i></span>
</div>
<span id="selected"></span>

JS:

 $(".form_datetime").datetimepicker({
   format: "dd MM yyyy - hh:ii",
   minView:1,
   autoclose:true
 });

 $("#first").datetimepicker().on("changeDate", function(e){     
  var first = new Date(e.date.setMinutes(0));
        first.setHours(first.getHours()+first.getTimezoneOffset()/60); //timezone correction

  $("#second").datetimepicker('setStartDate', first); 

  //other = $("#first").find("input").val(); 
  //$("#second").datetimepicker('setStartDate', other); //works also

 });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...