有没有办法改变输入类型=“日期"?格式? [英] Is there any way to change input type="date" format?

查看:35
本文介绍了有没有办法改变输入类型=“日期"?格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网页上处理 HTML5 元素.默认情况下,输入 type="date" 将日期显示为 YYYY-MM-DD.

I'm working with HTML5 elements on my webpage. By default input type="date" shows date as YYYY-MM-DD.

问题是,是否可以将其格式更改为:DD-MM-YYYY?

The question is, is it possible to change its format to something like: DD-MM-YYYY?

推荐答案

无法更改格式

我们必须区分在线格式和浏览器的演示格式.

We have to differentiate between the over the wire format and the browser's presentation format.

HTML5 日期输入规范 指的是 RFC 3339 规范,它指定的完整日期格式等于:<代码>yyyy-mm-dd.有关详细信息,请参阅 RFC 3339 规范的 第 5.6 节.

The HTML5 date input specification refers to the RFC 3339 specification, which specifies a full-date format equal to: yyyy-mm-dd. See section 5.6 of the RFC 3339 specification for more details.

此格式由 value HTML 属性和 DOM 属性使用,并且是在进行普通表单提交时使用的格式.

This format is used by the value HTML attribute and DOM property and is the one used when doing an ordinary form submission.

浏览器在如何呈现日期输入方面不受限制.在撰写本文时,Chrome、Edge、Firefox 和 Opera 具有日期支持(请参阅 此处).它们都显示一个日期选择器并格式化输入字段中的文本.

Browsers are unrestricted in how they present a date input. At the time of writing Chrome, Edge, Firefox, and Opera have date support (see here). They all display a date picker and format the text in the input field.

桌面设备

对于 Chrome、Firefox 和 Opera,输入字段文本的格式取决于浏览器的语言设置.对于 Edge,它基于 Windows 语言设置.遗憾的是,所有网络浏览器都忽略了操作系统中配置的日期格式.对我来说,这是非常奇怪的行为,并且在使用这种输入类型时需要考虑.例如,将操作系统或浏览器语言设置为 en-us 的荷兰用户将显示 01/30/2019 而不是他们习惯的格式:<代码>30-01-2019.

For Chrome, Firefox, and Opera, the formatting of the input field's text is based on the browser's language setting. For Edge, it is based on the Windows language setting. Sadly, all web browsers ignore the date formatting configured in the operating system. To me this is very strange behaviour, and something to consider when using this input type. For example, Dutch users that have their operating system or browser language set to en-us will be shown 01/30/2019 instead of the format they are accustomed to: 30-01-2019.

Internet Explorer 9、10 和 11 以有线格式显示文本输入字段.

Internet Explorer 9, 10, and 11 display a text input field with the wire format.

移动设备

特别是对于 Android 上的 Chrome,格式基于 Android 显示语言.我怀疑其他浏览器也是如此,尽管我无法验证这一点.

Specifically for Chrome on Android, the formatting is based on the Android display language. I suspect that the same is true for other browsers, though I've not been able to verify this.

这篇关于有没有办法改变输入类型=“日期"?格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆