Change input type='time' in dropdown

Viewed 797

So I have this input field, where the user has to enter their startime, and then I was wondering if it was possible to change the marked dropdown time to another? The dropdown starts at UTC+2 but I want it to start at UTC+0 so instead of 09:59 it should start at 07:59.

utc2

Would it be possible to use this Javascript timestamp to update the input time?

setInterval(time, 1000);
function time() {
    var span = document.getElementById('span');
    var d = new Date().toUTCString().split(' ')[4];
    span.textContent = "Current UTC+0 time: " + d;
}
<input class='form-control w-100' style='width:auto;' type='time' id='mt_start' name='mt_start' required>

<div class='d-flex justify-content-end fixed-top mt-5 mr-1' style='z-index: -1;'>
  <h3><span class='badge badge-secondary' id='span'>Current UTC+0 time: </span></h3>
</div>

2 Answers

You can set the value of the time input, like so:

<input type="time" value="19:59">

MDN

You can set the value of the input directly with document.querySelector('#mt_start').value. Use the time string that you save in the variable d:

document.querySelector('#mt_start').value = new Date().toUTCString().split(' ')[4];
<input type='time' id='mt_start'>

Related