0

I'm sending this to my view:

<%= @venue.eventdate %>

which displays a UTC date time. e.g. 2013-01-10 17:15:00 UTC

I found this site for strftime command and created a custom built. I foolishly added this to end of my object in my view like that:

<%= @venue.eventdate.strftime(%A, %e %B %Y at %l:%M %p) %>

e.g.(ideally) Thursday, 3 January 2013 at 4:08 AM

And of course it didn't work. Anyone know how make the correct conversion in a simple way?

Diolor
  • 13,181
  • 30
  • 111
  • 179
  • 1
    Don't really know if this is the origin of your problem but you forgot the double quotes : `<%= @venue.eventdate.strftime("%A, %e %B %Y at %l:%M %p") %>` – Raindal Jan 03 '13 at 04:33

2 Answers2

0

This is typically handled client side with something like JS given that the client is more aware of it's own locale.

Convert UTC date time to local date time using JavaScript

if you are bent on doing this server side

Display local time in view

Community
  • 1
  • 1
Hayk Saakian
  • 2,036
  • 2
  • 18
  • 31
0

Generally you can create your custom date method. First you create a date_formats.rb file in config/initializers and for example create a time format like this:

Time::DATE_FORMATS[:day_month_year] = "%A, %e %B %Y"

and use this method in view file like "to_formatted_s(:day_month_year)"

<%= object.eventdate.to_formatted_s(:day_month_year)%> <%= object.created_at.strftime("%I:%M %p")%>

Do not forget restart rails server after add date_formats.rb file.

kader
  • 31
  • 1
  • 4