ruby on rails - How do I split the value returned by created_at? -
i trying split value returned created_at
method.
i taking object (item
) , getting time created at. don't want whole result , interested in day, month , year. how can work?
<% @items_in_basket.each |item| %> <% splliter = item.created_at.split(" ") %> <% time = @splliter[0] %>
i result:
undefined method 'split' wed, 31 jul 2013 16:44:37 utc +00:00:time
created_at
returns instance of activesupport::timewithzone
can call day
, month
, or year
on parts of date. example:
<% @items_in_basket.each |item| %> day: <%= item.created_at.day %> month: <%= item.created_at.month %> year: <%= item.created_at.year %> <% end %>
this approach more reliable parsing string format returned to_s
.
Comments
Post a Comment