Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML input time in 24 format

Tags:

html

I am using below HTML tag:

<input type="time"  /> 

In Chrome, Its showing PM/AM format, can we restrict to display 24 format always. I dont want to use HTML5 tag

like image 801
Vikas Singh Avatar asked Sep 16 '15 13:09

Vikas Singh


People also ask

How do I change input type time in 24 hour format?

You can't do it with the HTML5 input type. There are many libs available to do it, you can use momentjs or some other jQuery UI components for the best outcome. Show activity on this post. In my case, it is taking time in AM and PM but sending data in 00-24 hours format to the server on form submit.

How can I get input time in HTML?

The <input type="time"> defines a control for entering a time (no time zone).


1 Answers

As stated in this answer not all browsers support the standard way. It is not a good idea to use for robust user experience. And if you use it, you cannot ask too much.

Instead use time-picker libraries. For example: TimePicker.js is a zero dependency and lightweight library. Use it like:

var timepicker = new TimePicker('time', {   lang: 'en',   theme: 'dark' }); timepicker.on('change', function(evt) {      var value = (evt.hour || '00') + ':' + (evt.minute || '00');   evt.element.value = value;  });
<script src="https://cdn.jsdelivr.net/timepicker.js/latest/timepicker.min.js"></script> <link href="https://cdn.jsdelivr.net/timepicker.js/latest/timepicker.min.css" rel="stylesheet"/>  <div>   <input type="text" id="time" placeholder="Time"> </div>

More info about the time input can be found on MDN Web Docs

like image 193
Gokhan Kurt Avatar answered Sep 21 '22 15:09

Gokhan Kurt