如何在 HTML 日期输入标签中设置日期格式? [英] How to set date format in HTML date input tag?

查看:68
本文介绍了如何在 HTML 日期输入标签中设置日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在html <input type="date"></input>标签中设置日期格式...目前是yyyy-mm-dd,而我需要它的 dd-mm-yyyy 格式.

解决方案

你没有.

首先,您的问题是模棱两可的 - 您是指向用户显示的格式,还是传输到网络服务器的格式?

如果您指的是向用户显示的格式,那么这取决于最终用户界面,而不是您在 HTML 中指定的任何内容.通常,我希望它基于操作系统区域设置中设置的日期格式.尝试用您自己喜欢的格式覆盖它是没有意义的,因为它显示的格式(一般来说)是用户语言环境的正确格式,也是用户用来书写/理解日期的格式.

如果您指的是传输到服务器的格式,那么您正在尝试解决错误的问题.您需要做的是编写服务器端代码以接受 yyyy-mm-dd 格式的日期.

I am wondering whether it is possible to set the date format in the html <input type="date"></input> tag... Currently it is yyyy-mm-dd, while I need it in the dd-mm-yyyy format.

解决方案

You don't.

Firstly, your question is ambiguous - do you mean the format in which it is displayed to the user, or the format in which it is transmitted to the web server?

If you mean the format in which it is displayed to the user, then this is down to the end-user interface, not anything you specify in the HTML. Usually, I would expect it to be based on the date format that is set in the operating system locale settings. It makes no sense to try to override it with your own preferred format, as the format it displays in is (generally speaking) the correct one for the user's locale and the format that the user is used to writing/understanding dates in.

If you mean the format in which it's transmitted to the server, you're trying to fix the wrong problem. What you need to do is program the server-side code to accept dates in yyyy-mm-dd format.

这篇关于如何在 HTML 日期输入标签中设置日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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