-3

Using <input type="date"/>, <input type="datetime-local"/> or <input type="time"/> will display date and time as either:

date:     dd/mm/yyyy
datetime: dd/mm/yyyy, hh:mm:ss
time:     hh:mm:ss

However, in my language, / is not used as the date separator, instead . is used. . is also the preferred separator for time (although : is accepted), so I would like these inputs to show up as:

date:     dd.mm.yyyy
datetime: dd.mm.yyyy at hh.mm.ss
time:     hh.mm.ss

Can this be done natively with these HTML input types, or does this have to be implemented with custom inputs?

A solution should be locale-dependent (so . shouldn't be a hardcoded separator), and in pure HTML. A negative answer is also accepted if browsers currently do not support this.

From 4.10.7.1.12 Local Date and Time state:

The format shown to the user is independent of the format used for form submission. Browsers are encouraged to use user interfaces that present dates and times according to the conventions of the user's preferred locale.

Frank Vel
  • 1,202
  • 1
  • 13
  • 27
  • Change the dupe I found to `data-date-format="DD.MM.YYYY" ` – mplungjan Aug 13 '23 at 09:06
  • @mplungjan That duplicate does not provide a locale-specific solution, but applies to a specific format. How can I best rephrase this question so that becomes clearer? – Frank Vel Aug 13 '23 at 09:34
  • The solution on the linked question also uses JavaScript/JQuery, which I would like to avoid. Solution should be in HTML. No solution is also accepted if this is not possible. – Frank Vel Aug 13 '23 at 09:40
  • 1
    Note that the [](https://html.spec.whatwg.org/dev/embedded-content.html#the-input-element) tag does not use and does not need a closing slash and never has in any HTML specification. – Rob Aug 13 '23 at 11:27
  • Although [the solution in the dupe I posted earlier](https://stackoverflow.com/questions/72996218/how-to-change-html-input-date-format-default-to-mm-dd-yyyy) is in jQuery but it is trivial to convert to plain JS. There is no HTML way what so ever. Just because you want an HTML method does not mean one exists so the answer is "No it cannot be done without JS" – mplungjan Aug 13 '23 at 11:30
  • So a better dupe could be [this](https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format) – mplungjan Aug 13 '23 at 11:33
  • @mplungjan I'm happy to accept that as an answer if you post it. Hopefully browsers will implement that, so that it will be possible in the future. – Frank Vel Aug 13 '23 at 11:35
  • It is a dupe of the link in [the last comment](https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format) I made – mplungjan Aug 13 '23 at 11:36
  • Yes, that would be a duplicate, thank you. – Frank Vel Aug 13 '23 at 11:38
  • Specifically, this question is about the presentation format. – Frank Vel Aug 13 '23 at 11:39
  • 1
    @Rob Trailing slashes are in the [HTML5 syntax](https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#syntax-elements) specification: "*Optionally, a "/" character, which may be present only if the element is a void element.*" They are optional as you say, but are useful for compatibility with XHTML. – Frank Vel Aug 13 '23 at 11:45
  • The closing slash being allowed is for historical reasons but carries no meaning, it does nothing, and browsers ignore it. The W3C Validator will flag it. [Trailing slashes do not mark elements as self-closing](https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements#trailing-slashes-in-void-element-start-tags-do-not-mark-the-start-tags-as-self-closing) – Rob Aug 13 '23 at 11:57
  • [Trailing slashes has no effect](https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements#suppressing-the-trailing-slash-on-void-elements-has-no-effect-message) – Rob Aug 13 '23 at 11:58
  • In fact, they [can cause harm](https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements#trailing-slashes-directly-preceded-by-unquoted-attribute-values) – Rob Aug 13 '23 at 11:59
  • In any case, as I said earlier, no HTML specification has ever told you to put them there. – Rob Aug 13 '23 at 12:01
  • If you want compatibility with XHTML, that game is lost as it's difficult to be compatible with XHTML and HTML at the same time (starting with the doctype and application type alone). – Rob Aug 13 '23 at 12:11

0 Answers0