开发者

Formatting Date Output Hash

开发者 https://www.devze.com 2023-03-06 20:11 出处:网络
The output from my hash is giving me the following date time: 开发者_如何学JAVA16 May 11 13:12:14 +0000

The output from my hash is giving me the following date time:

开发者_如何学JAVA
16 May 11 13:12:14 +0000

How do I go about formatting this into something sensible?

Thanks


I'll assume you are wanting this output in a view... First, you can create some formats:

# /config/locales/en.yml:
en:
  date:
    formats:
      full: "%b %d, %Y"

  time:
    formats:
      full: "%B %d, %Y at %I:%M%p"

Then you can display a datetime in a view using the l method with specified format:

<%= l @something.updated_at, :format => :full %>

This would display something like the following:

May 16, 2011 at 01:12pm

More on the i18n formats

List of available directives

0

精彩评论

暂无评论...
验证码 换一张
取 消