1

Need help with making time format from 12 hours to 24 hours. I removed am/pm marks and now I have no clue how to change it to 24 hours.

I'm not familiar with Javascript so that cause me problems. Maybe someone could give me code in details how to make?

.without::-webkit-datetime-edit-ampm-field {
  display: none;
}
<input type="time" id="time" name="bday" value="21:00" step="1800" min="00:00" max="23:59" required class="without" autofocus>
Rokas Valadka
  • 37
  • 1
  • 1
  • 5
  • [https://stackoverflow.com/questions/22347521/change-time-format-to-24-hours-in-javascript](https://stackoverflow.com/questions/22347521/change-time-format-to-24-hours-in-javascript) – RompePC Jun 27 '17 at 07:14
  • It works fine at me (I can even set eg `23:30`). Please be aware that `input type="time"` is not widely supported ( * looks to Firefox... * ) and that it **depends** of the locale. – KarelG Jun 27 '17 at 07:18
  • Looks good on mozilla but not chrome. Also it disables navigation arrows in mozilla cant navigate through with 30 min (step="1800") intervals. – Rokas Valadka Jun 27 '17 at 08:08

3 Answers3

0

Different browsers show a different response to this input type="time". Tried Chrome, Firefox, Edge & IE. Your best bet is to write custom javascript functions to handle input events.

Note:

<input type="time" id="time">
<input type="time" id="time" name="bday" pattern="([1]?[0-9]|2[0-3]):[0-5][0-9]">

These templates work in older browsers but not in the latest versions of Chrome and Firefox and show 12-hour format.

leonheess
  • 16,068
  • 14
  • 77
  • 112
Raheel Anwar
  • 267
  • 2
  • 10
0

In razor pages, in Chrome browser:

 <input type="datetime-local" name="<>" id="<>" value=@string.Format("{0:yyyy-MM-ddTHH:mm}",Model.<your model name>)/>

HH means 24-hour format. hh means AM/PM format

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28
-3

The following works without the need for Javascript

<input type="time" id="time" name="bday" pattern="([1]?[0-9]|2[0-3]):[0-5][0-9]"/>
Gerard
  • 15,418
  • 5
  • 30
  • 52
  • On my laptop, which is set to english and on firefox, this input type shows 12h AM/PM format. So it probably works only on your machine with local settings. – mike May 23 '20 at 21:41