locked
set time time in picker RRS feed

  • Question

  • User1259588416 posted

    I have two time picker and a text box . I need when page loads then  one time picker say timePickerFrom  should set current time and another  timepicker say timepickerTo  to

     current time    plus 10 min  and difference should store in text box. Now when time is change in any time picker then its difference should store in textbox.

    can any one tell how i can do this ? demonstration in fidder would be nice

    Thursday, November 5, 2015 1:20 PM

Answers

  • User503812343 posted

    try below code 

    <script src="//code.jquery.com/jquery-1.10.2.js" 
                type="text/javascript"></script>
    <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js" 
                type="text/javascript"></script>

    $('#range_example_2_start').val($.now())
    
    var tenMinutesLater = new Date();
    tenMinutesLater.setMinutes(tenMinutesLater.getMinutes() + 10);
    $('#range_example_2_end').val(tenMinutesLater);
    
    var startDateTextBox = $('#range_example_2_start');
    var endDateTextBox = $('#range_example_2_end');
    
    $.timepicker.datetimeRange(
    	startDateTextBox,
    	endDateTextBox,
    	{
    		minInterval: (1000*60*60), // 1hr
    		dateFormat: 'dd M yy', 
    		timeFormat: 'HH:mm',
    		start: {}, // start picker options
    		end: {} // end picker options					
    	}
    );

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 6, 2015 12:23 AM
  • User61956409 posted

    Hi kaushiklotus,

    Please refer to the following code to get the current time and add 10 minutes to it. Then you could set default selected time for your timepicker.

    <script>
        $(function () {
            var date1 = new Date();
            var timefrom = "";
            var timeto = "";
    
            timefrom = date1.toLocaleTimeString();
    
            date1.setMinutes(date1.getMinutes() + 10);
            timeto = date1.toLocaleTimeString();
    
            alert(timefrom + "/" + timeto);
    
            //set default time for "timePickerFrom" and "timepickerTo"
        })
    </script> 
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 6, 2015 12:29 AM

All replies

  • User503812343 posted

    try below code 

    <script src="//code.jquery.com/jquery-1.10.2.js" 
                type="text/javascript"></script>
    <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js" 
                type="text/javascript"></script>

    $('#range_example_2_start').val($.now())
    
    var tenMinutesLater = new Date();
    tenMinutesLater.setMinutes(tenMinutesLater.getMinutes() + 10);
    $('#range_example_2_end').val(tenMinutesLater);
    
    var startDateTextBox = $('#range_example_2_start');
    var endDateTextBox = $('#range_example_2_end');
    
    $.timepicker.datetimeRange(
    	startDateTextBox,
    	endDateTextBox,
    	{
    		minInterval: (1000*60*60), // 1hr
    		dateFormat: 'dd M yy', 
    		timeFormat: 'HH:mm',
    		start: {}, // start picker options
    		end: {} // end picker options					
    	}
    );

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 6, 2015 12:23 AM
  • User61956409 posted

    Hi kaushiklotus,

    Please refer to the following code to get the current time and add 10 minutes to it. Then you could set default selected time for your timepicker.

    <script>
        $(function () {
            var date1 = new Date();
            var timefrom = "";
            var timeto = "";
    
            timefrom = date1.toLocaleTimeString();
    
            date1.setMinutes(date1.getMinutes() + 10);
            timeto = date1.toLocaleTimeString();
    
            alert(timefrom + "/" + timeto);
    
            //set default time for "timePickerFrom" and "timepickerTo"
        })
    </script> 
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 6, 2015 12:29 AM