简体   繁体   English

将@ project.end_date.strftime(“%b%Y”)转换为定义的语言环境

[英]Converting @project.end_date.strftime(“%b %Y”) to defined locale

I'm outputting Date attributes with the following method 我正在使用以下方法输出Date属性

@project.end_date.strftime("%b %Y")

What is the simplest way to localize this date such that it displays in the locale defined in application.rb ? 将日期本地化以使其显示在application.rb定义的语言环境中的最简单方法是什么?

The simplest way to do this is to use Rails' #l helper method like so: 最简单的方法是使用Rails的#l helper方法,如下所示:

l @project.end_date

You can also use a format you defined in locales .yml file: 您还可以使用在语言环境.yml文件中定义的格式:

l @project.end_date, format: :short

# config/locales/pirate.yml
pirate:
  time:
    formats:
      short: "arrrround %H'ish"

The Rails guide covers this. Rails指南对此进行了介绍。 Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM