更改Rails 4中的默认日期和时间格式 [英] Changing the default date and time format in Rails 4

查看:123
本文介绍了更改Rails 4中的默认日期和时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来更改Rails 4中的默认日期格式。

I was looking for a way to change the default date format in Rails 4.

推荐答案

通过 Rails国际化(I18n)API

通过将格式添加到i18n配置中可以转换数据和时间格式。

Data and time formats can be 'translated' by adding the format to the i18n configuration.

config / locales / en.yml

config/locales/en.yml

en:
  date:
    formats:
      default: "%d/%m/%Y"
  time:
    formats:
      default: "%d/%m/%Y %H:%M"

注意:记得没有缩进的标签,就像我第一次做的那样:)

Note: remember to not have tabs for the indent, like I did first time :)

您被邀请如果您发现其他方式运作良好,请发表评论。

You are invited to comment if you found other ways working well.

这篇关于更改Rails 4中的默认日期和时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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