Rails 日期字段格式错误

发布于 2024-08-27 11:56:45 字数 260 浏览 13 评论 0原文

我有一个输入字段,用于捕获表单中的日期

<%= f.text_field :from_date, :style => 'width:80px;' %>

用户按以下格式输入日期 MM/DD/YYYY。但是,当模型中存在验证错误并且表单与输入的值一起显示给用户时,日期格式将转换为 YYYY-MM-DD HH:MM:SS UTC。当向用户显示表单时,我应该在哪里设置格式以显示 MM/DD/YYYY。

谢谢。

I have an input field that captures a date in my form

<%= f.text_field :from_date, :style => 'width:80px;' %>

The user enters the date in the following format MM/DD/YYYY. However, when there is a validation error in the model and the form is displayed back to the user with the entered values, the date format is converted to YYYY-MM-DD HH:MM:SS UTC. Where do I format this to show MM/DD/YYYY, when the form is displayed to the user.

thanks.

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

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

发布评论

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

评论(1

假面具 2024-09-03 11:56:45

尝试以下 &用你的日期代替@date
<%= f.text_field :from_date, :style =>; '宽度:80px;',:值=>(@date.blank?)? '' : @date.strftime('%m/%d/Y') %>

Try following & put your date in place of the @date
<%= f.text_field :from_date, :style => 'width:80px;', :value=>(@date.blank?)? '' : @date.strftime('%m/%d/Y') %>

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