Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format ActiveSupport::TimeWithZone instance to specified format

I have a ActiveSupport::TimeWithZone instance like 2014-12-22 05:54:34 UTC, but I only want to keep the date info 2014-12-22

I tried Rail's to_formatted_s, but it didn't work for me.

<%= item.updated_at.to_formatted_s(:db) %>

Which displays: 2014-12-22 05:54:34

like image 758
lazybios Avatar asked Dec 22 '14 06:12

lazybios


1 Answers

You can use strftime:

> date_time.strftime('%Y-%m-%d')

where,

%Y - Year with century
%m - Month of the year (01..12)
%d - Day of the month (01-31)
like image 160
vee Avatar answered Nov 14 '22 22:11

vee