ruby - How to display DateTimes with am/pm without using custom formatting in Rails -
currently display datetime
s in rails with:
my_time.to_formatted_s(:long_ordinal)
that produces date like:
march 17th, 2014 14:44
perfect except 14:44
time. want 2:44pm (how 'pm' formatted doesn't matter me). needs easier common person read. know can use:
my_time.strftime('%l:%m %p')
however, i'd use predefined symbol more human readable format, because i'd more human readable in language. if browsing different language datetime
s naturally little different, i'm hoping rails can, or @ least set to, automatically display datetime
nicely. maybe i'm expecting of rails there? seems strange me though there isn't simple flag or setting more human readable datetime
format.
in case can add own humanized format
# config/initializers/time_formats.rb time::date_formats[:custom_long_ordinal] = "%b %e, %y %l:%m %p"
and use with
my_time.to_formatted_s(:custom_long_ordinal)
Comments
Post a Comment