Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

html5 - 有什么办法可以更改输入类型=“日期”格式?(Is there any way to change input type=“date” format?)

I'm working with HTML5 elements on my webpage.

(我正在使用网页上的HTML5元素。)

By default input type="date" shows date as YYYY-MM-DD .

(默认情况下,输入type="date"显示为YYYY-MM-DD 。)

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

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

  ask by Tural Ali translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is impossible to change the format

(无法更改格式)

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

(我们必须区分有线格式和浏览器的演示格式。)

Wire format (电汇格式)

The HTML5 date input specification refers to the RFC3339 specification , which specifies a full-date format equal to: yyyy-mm-dd .

(所述HTML5日期输入规范指的是RFC3339规范 ,它指定一个全日期格式等于: yyyy-mm-dd 。)

See section 5.6 of the RFC3339 specification for more details.

(有关更多详细信息,请参见RFC3339规范的5.6节 。)

Presentation format (简报格式)

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 ).

(在撰写本文时,Chrome,Edge,Firefox和Opera具有日期支持(请参阅此处 )。)

They all display a date picker and format the text in the input field.

(它们都显示日期选择器,并在输入字段中设置文本格式。)

Desktop devices

(桌面设备)

For Chrome, Firefox, and Opera, the formatting of the input field's text is based on the browser's language setting.

(对于Chrome,Firefox和Opera,输入字段文本的格式基于浏览器的语言设置。)

For Edge, it is based on the Windows language setting.

(对于Edge,它基于Windows语言设置。)

Sadly, all web browsers ignore the date formatting configured in the operating system.

(可悲的是,所有Web浏览器都忽略了操作系统中配置的日期格式。)

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 .

(例如,将其操作系统或浏览器语言设置为en-us荷兰用户将显示01/30/2019而不是他们习惯的格式: 30-01-2019 。)

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

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

Mobile devices

(移动设备)

Specifically for Chrome on Android, the formatting is based on the Android display language.

(专门针对Android上的Chrome,格式基于Android显示语言。)

I suspect that the same is true for other browsers, though I've not been able to verify this.

(我怀疑其他浏览器也是如此,尽管我无法对此进行验证。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...