问题描述
我有点问题。我正在开发一个Web系统,表单字段类型日期让我很头疼。该系统仅适用于巴西用户,则日期格式应为dd / mm / yyyy。当从具有葡萄牙语的计算机访问该站点时,HTML表单字段类型的日期以我想要的方式工作。但是当以计算机语言访问网站时,英文日期格式变为yyyy-mm-dd。这是一个问题,因为有时用户甚至没有注意到您的计算机的日期格式已更改,但用户希望以dd / mm / yyyy格式查看日期。
I have a little problem. I am developing a web system and the form field type date is giving me a headache. The system will be for Brazil only users, then the date format should be dd/mm/yyyy. When access the site from a computer with the Portuguese language, the date of the HTML form field type works the way I want. But when access the site in a computer language English date format becomes yyyy-mm-dd. This is a problem because sometimes user does not even notice that your computer's date format is changed, but the user wants to see the date in the format dd/mm/yyyy.
我需要的是格式为dd / mm / yyyy,无论访问网站的机器设置如何,也不使用任何其他javascript库。
What I need is that the format is dd/mm/yyyy regardless of machine settings to access the site, and without using any additional javascript library.
使用的代码是:
<input type="date" id="date">
推荐答案
没有这样的事情。 输入类型=日期
将获取您的系统默认值,并在GUI中显示该值,但始终以ISO格式(yyyy-mm-dd)存储该值。除此之外,请注意并非所有浏览器都支持此功能,因此依赖此输入类型并不是一个好主意。
No such thing. the input type=date
will pick up whatever your system default is and show that in the GUI but will always store the value in ISO format (yyyy-mm-dd). Beside be aware that not all browsers support this so it's not a good idea to depend on this input type yet.
如果这是一个公司问题,请强制所有计算机使用本地区域格式(dd-mm-yyyy),您的UI将以此格式显示(更改区域设置之前请参阅wufoo链接,您需要重新打开浏览器)。
If this is a corporate issue, force all the computer to use local regional format (dd-mm-yyyy) and your UI will show it in this format (see wufoo link before after changing your regional settings, you need to reopen the browser).
-
请参阅:例如
请参阅:
请参阅:。 < - 没有格式attr。
See: http://www.w3.org/TR/html-markup/input.date.html for spec. <- no format attr.
您最好的选择仍然是使用基于JavaScript的组件,以便您自定义这可以随心所欲。
Your best bet is still to use JavaScript based component that will allow you to customize this to whatever you wish.
这篇关于如何强制输入日期格式为dd / mm / yyyy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!