0

I am using this I18n file.

I am calling it in my view like this:

<td class="center"><%= l o.created_at %></td>

This is being outputted like this:

Mon, 22 May 2013 04:04:43 +0000

For starters, why is it displaying May 22, 2013 and not April 22?

When I do it in the console, I get this:

> o.created_at
 => Mon, 22 Apr 2013 04:04:43 UTC +00:00 

I don't want it to display the time, or rather would prefer to just say something like:

Monday, April 22, 2013 @ 4:04am

How do I do that?

marcamillion
  • 32,933
  • 55
  • 189
  • 380

1 Answers1

1

You can add custom date/time formats to your translation file. To see what time-based substitutions are possible, consult a reference for strfime

formats:
  default: ! '%Y-%m-%d'
  long: ! '%B %d, %Y'
  short: ! '%b %d'
  custom: ! '%A, %M %B, %Y @ %l:%M%P'

In your view, you'd make use as follows:

<%= l o.created_at, :format => :custom %>

You may need to get rid of blank entries in your en.yml file to correct your translation errors.

rossta
  • 11,394
  • 1
  • 43
  • 47
  • When I used that, I get this error: `: #` Where `line 39` is the `custom` line. Thoughts? – marcamillion Apr 23 '13 at 03:34
  • It means Psych, the yaml parser your Rails app is using, can't parse the token starting at line 39 of your yaml file. This often happens when making typos or copying & pasting code from the web. I can't tell without seeing your yaml file. – rossta Apr 23 '13 at 03:46
  • I can't reproduce the error, but I noticed your indent is off and you may need to add the "custom" bit to the `time` formats. What versions of Rails/Ruby/Psych are you using? – rossta Apr 23 '13 at 03:55
  • I am using Rails 3.2.12/Ruby 1.9.3/no clue Psych. – marcamillion Apr 23 '13 at 04:08
  • Try `Psych::VERSION` on the console – rossta Apr 23 '13 at 04:13
  • Wow....it is the spacing. I had tabbed and did 3 spaces and that seems to have been throwing it off. I finally got it working. Thanks! – marcamillion Apr 23 '13 at 04:14
  • The thing is, I had to move it into the `Time` section, and am now getting `May` instead of `April`. But I have removed the empty `-` in the month_names. What could be causing it? Here is my updated YAML file - https://gist.github.com/marcamillion/3c250178af9bf48e9a3d – marcamillion Apr 23 '13 at 04:23