Thursday, 21 April 2016

html5 - Is there any way to change input type="date" format?



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



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


Answer



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. See section 5.6 of the RFC3339 specification for more details.



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). 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. 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, and 11 display a text input field with the wire format.



Mobile devices



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.



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...