0

please need a code to display dynamically time in drop down box or select tag and if current time display in drop down box and in drop down should display after current time then 1.30 hours time.

Example:- now time is 12.00 AM in drop down should display 1.30 AM up to 12.00. It calculate by half hour. If time is now 2.00 PM should display from 1half hour after like this 3.30 PM up to 12.00 AM by calculating half hour.

And i can display in text but i need to display in drop down box with current time display in drop down should be after 1.30 hours time up to 12.00 AM.

    function display_c(){
    var refresh=1000; 
    mytime=setTimeout('display_ct()',refresh)
    }
    
    function display_ct() {
    var strcount
    var dt = new Date()
    var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
    
    document.getElementById('t1').value = time;
    tt=display_c();
    
     }
    <input type=text id='t1' size='10'>
    <span id='ct' ></span>
Mukul Kant
  • 7,074
  • 5
  • 38
  • 53

1 Answers1

0

You can use setInterval to call a function after waiting some seconds: demo on fiddle

display_c();
function display_c(){
    setInterval(function(){display_ct()}, 3000);
}

function display_ct() {
    console.log('test');
    var strcount;
    var dt = new Date();
    var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();

    document.getElementById('t1').value = time;
    tt=display_c();
}
Matthieu
  • 221
  • 1
  • 11
  • i need to display in dropdown box. its in text but i need in dropdown. – Ahmed Muba Nov 13 '14 at 07:36
  • You have the code to display the current time on a input text (variable dt). Now you just have to add 30minutes and display result in an option tag. Then repeat "x" times. See here: [how to add option in select with js vanilla](http://stackoverflow.com/questions/17730621/how-to-dynamically-add-options-to-an-existing-select-in-vanilla-javascript?answertab=votes#tab-top) – Matthieu Nov 13 '14 at 07:40
  • ya but i need in dropdown box option. current time should display in dropbox with one half hour difference from there by half hour. – Ahmed Muba Nov 13 '14 at 08:12