简体   繁体   English

输入类型时间24小时格式

[英]Input type time 24 hour format

Too many this type of old questions are already in Stack Overflow, but now I would like to know any new method to fix this problem! Stack Overflow中已经有太多此类旧问题,但现在我想知道任何解决此问题的新方法!

 <input type="time">

How can we change this 12hr to 24hr format for all browsers?我们如何将所有浏览器的12 小时格式更改为 24 小时格式? It would be great this will work with only JavaScript and without any third party JS/Jquery.仅适用于 JavaScript而无需任何第三方 JS/Jquery 会很棒。 Can any one help?任何人都可以帮忙吗?

Referenced questions:参考问题:

HTML input time in 24 format 24 格式的 HTML 输入时间

html5 time inputs shows 12 hours html5 时间输入显示 12 小时

Try This Using time-picker libraries. 试试这个使用时间选择器库。 For example: DateTimePicker.js is a zero dependency and lightweight library. 例如: DateTimePicker.js是一个零依赖和轻量级库。 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="http://cdn.jsdelivr.net/timepicker.js/latest/timepicker.min.js"></script> <link href="http://cdn.jsdelivr.net/timepicker.js/latest/timepicker.min.css" rel="stylesheet"/> <div> <input type="text" id="time" placeholder="Time"> </div> 

From documentation : 来自文档

The value of the time input is always in 24-hour format: "hh:mm", regardless of the input format, which is likely to be selected based on the user's locale (or by the user agent) . 时间输入的值始终为24小时格式:“hh:mm”,无论输入格式如何, 都可能根据用户的区域设置(或用户代理)进行选择

So you need to change locale to get in 24hrs format. 因此,您需要更改区域设置以获得24小时格式。

That came to mind when I opened your same question on 2 different laptops. 当我在2台不同的笔记本电脑上打开同样的问题时,我想到了这一点。 One is showing 24hrs format and other is showing 12hrs format. 一个显示24小时格式,另一个显示12小时格式。

You need to set locale in your project which has 24hrs format. 您需要在项目中设置24小时格式的区域设置。

Example: 'ja-JP' , 'en-GB' has 24hrs format 示例: 'ja-JP''en-GB'具有24小时格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM