Kamran Hassan
Kamran Hassan

Reputation: 139

How to get time value from jquery timepicker.?

I am trying to get values from i select time in my time picker but so far I am not getting any values in return and not even in my html timepicker input showing any value inside,

I tried some methods but not successful yet,

Method 1:

$('#datetimepicker4').on('selectTime', function() {
    var time = $('#datetimepicker4').timepicker('getTime');
    alert(time);
    // this will be a Date object that includes the time
});

Method 2:

$("#datetimepicker4").on('change paste keyup', function(){
    var time = $(this).val();
    alert(time);
    var getTime = time.split(":"); //split time by colon
    var hours = parseInt(getTime[0])+2; //add two hours
    //set new time
    var newTime = hours+":"+getTime[1];
    //set time picker
    $("#datetimepicker5").timepicker('option',{'minTime': newTime});
});

I am debugging by try alert even not getting alert so my both functions are not working that means, even no console error relate to time pickers for selection I found, I want to be able to set min time 3 hours for current time.

Upvotes: 3

Views: 8855

Answers (1)

Negi Rox
Negi Rox

Reputation: 3922

i don't think so you need a getTime you can simply select input box value.

(function($) {
    $(function() {
        $('input.timepicker').timepicker();
        $("#getdate").on('click',function(){
           $("#time").text($("#timepicker").val())
        })
    });

})(jQuery);

if you want on change of timepicker use below code

 $('document').ready(function(){
                $('#time').timepicker();
                $('#time').on('changeTime', function() {
                    var x = $("#time").val();
                    $('#d_time').text(x);
                });
            });

see working example here

updated fiddle

Upvotes: 2

Related Questions