指定 HTML5 输入类型 = 日期的值输出?

发布于 2024-09-14 17:58:08 字数 190 浏览 2 评论 0原文

我想将本机日期选择器添加到我的应用程序中,该应用程序当前使用遗留的本地系统。日期输入支持尚未广泛普及,但如果我可以基于兼容性提供这两种实现,那就太理想了。

有没有办法指定 HTML 日期选择器给出的值的输出? Opera 的默认值是 yyyy-mm-dd,我非常明确地需要 dd-MMM-yyyy。

目前有什么办法可以控制这个输出吗?

I'd like to add native date pickers to my application, which currently uses a legacy, home-rolled system. Date input support isn't widespread, yet, but if I could present both implementations based on compatibility, that would be ideal.

Is there any way to specify the output of the value given by an HTML datepicker? The default for opera is yyyy-mm-dd, and I very explicitly need dd-MMM-yyyy.

Is there any way to control this output, currently?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风苍溪 2024-09-21 17:58:08

HTML5 日期输入 字段特定于其使用的格式:
RFC 3339 完整日期

是否可以更改旧的日期选择器使用 yyyy-mm-dd 格式(并更新读取该格式的服务器端)?

我认为不是,所以您可以添加一些 Javascript 粘合代码,用于侦听 HTML5 输入上的更改事件并更新隐藏的日期值字段以匹配旧日期选择器的格式(将 yyyy-mm-dd 转换为 dd-MMM -yyyy)。

The HTML5 date input field is specific about the format it uses:
RFC 3339 full-date

Is it possible to change the legacy date picker to use yyyy-mm-dd format (and update the server side that reads that)?

I assume not, so then you can add some Javascript glue code that listens for a change event on the HTML5 input and updates a hidden date value field to match the format of the legacy date picker (converts yyyy-mm-dd to dd-MMM-yyyy).

别闹i 2024-09-21 17:58:08

在 Google Chrome 中,这种情况最近发生了变化。现在向用户显示的值基于操作系统区域设置。然而,无论呈现格式如何,读数(即 input.value)始终返回为 yyyy-mm-dd

我认为更有用。

来源:

http://updates .html5rocks.com/2012/08/Quick-FAQs-on-input-type-date-in-Google-Chrome

In Google Chrome, this has recently changed. The values displayed to the user are now based on the operating system locale. The readout, so input.value, always returns as yyyy-mm-dd regardless of the presentation format, however.

Way more useful in my opinion.

Source:

http://updates.html5rocks.com/2012/08/Quick-FAQs-on-input-type-date-in-Google-Chrome

十级心震 2024-09-21 17:58:08

HTML 日期字段的格式是标准的。虽然无法更改此设置,但只要您的用户启用了 JavaScript,您就可以轻松地将日期对象转换为您正在查找的格式。

// Converts any valid Date string or Date object into the format dd-MMM-yyyy
function dateTransform(d) {
    var s = (new Date(d)).toString().split(' ');
    return [s[2],s[1],s[3]].join('-');
}

否则,您将需要以 ISO 格式提交并实施服务器端解决方案。也许随着时间的推移,这可能会导致每个地方更多地使用标准日期格式。

The format of the HTML date field is standard. While it is not possible to change this, you can easily convert from a date object to the format you are looking for given your user has JavaScript enabled.

// Converts any valid Date string or Date object into the format dd-MMM-yyyy
function dateTransform(d) {
    var s = (new Date(d)).toString().split(' ');
    return [s[2],s[1],s[3]].join('-');
}

Otherwise you will need to submit in ISO format and implement a server-side solution. Perhaps in time, this could lead to more usage of the standard date format in every locality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文