skip to Main Content

I’m working on a small Angular application, and I’m using the following HTML element for when the user sets the start hours:

<input type="time">

I’ve noticed that this element adopts either the 12-hour or 24-hour format based on the user’s system locale. Is there a way to consistently enforce the use of the 24-hour format for this element, regardless of the system locale?

Or alternatively, are there any JavaScript workarounds available?

2

Answers


  1. You can use the TimePicker.js library:

    <tr>
      <th>Start:</th>
      <td>
        <input type="text" id="start" name="start" />
      </td>
    </tr>
    

    Full Code

    https://jsfiddle.net/SeiryuV/qzn12um3/12/

    Login or Signup to reply.
  2. Is there a way to consistently enforce the use of the 24-hour format for this element, regardless of the system locale?

    No, and (per MDN):

    In unsupported browsers, the control degrades gracefully to <input type="text">

    which is even less strict.

    If your UI requirements differ from what is afforded by browsers, then you must implement (or find) a custom input that meets those requirements, including validation of the user input.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search