Home > OS >  JavaScript - Get and display current time in <input type="time">
JavaScript - Get and display current time in <input type="time">

Time:12-14

How do I display the current time in an input whose type is time and hide its picker icon?

Thank you all.

CodePudding user response:

You can set the input's valueAsDate property to the current date.

You can use the ::-webkit-calendar-picker-indicator pseudo-class to select the picker icon.

input.valueAsDate = new Date()
input[type="time"]::-webkit-calendar-picker-indicator {
    background: none;
}
<input type="time" id="input">

  • Related