可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am using below HTML tag:
In Chrome, Its showing PM/AM format, can we restrict to display 24 format always.
I dont want to use HTML5 tag
回答1:
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;
});
回答2:
There isn't a way to do this yet because the type=time element is really new.
https://www.w3.org/TR/2012/WD-html-markup-20120315/input.time.html has a list of valid attributes...
EDIT Fixed broken link
回答3:
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.
回答4:
Time:
Click the button to get the time of the time field.
Try it
function myFunction() {
var x = document.getElementById("myTime").value;
document.getElementById("demo").innerHTML = x;
}
I found that by setting value field (not just what is given below) time input will be internally converted into the 24hr format.