我的问题是如何以 21-01-1999 的格式而不是 01-21-1999 的格式在 HTML 表单中输入日期? 当我编写这段 HTML 代码时
<input name = "dPregled" id="dat" type="date" required="required" />
</p>
它为我提供了 mm-dd-yyyy 格式的输入。 还有一种方法可以自动在表单中获取今天的日期吗?
我一直在到处寻找答案,但找不到。 非常感谢你。
最佳答案
通过 Google 快速搜索,我可以找到您问题的大量答案。
来自https://developers.google.com/web/updates/2012/08/Quick-FAQs-on-input-type-date-in-Google-Chrome?hl=en (因此这适用于 Chrome)
Web authors have no way to change the date format because there currently is no standards to specify the format.
其余的,根据Is there any way to change input type="date" format?和 How to set date format in HTML date input tag? ,目前无法更改日期格式。这完全取决于您的浏览器/操作系统,并且由于尚未规范如何更改日期格式,因此您目前无法更改格式。
但是
上面提到的 Stack Overflow 帖子已经很老了,但是最近的答案之一(目前是 Is there any way to change input type="date" format? 上的第二个答案)确实提供了有关如何编辑格式的答案,尽管它需要一些我所知道的内容会调用一些高级的东西。您可以使用 HTML5 和影子 DOM 来实现这一点,这使您或多或少能够创建自己的 HTML 元素。不过,较旧的浏览器/浏览器版本通常不太支持它,但您可以深入研究一下,看看它是否适合您。
关于html - 如何将 html 中的日期格式从 mm-dd-yyyy 更改为 dd-mm-yyyy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39180747/