Skip to content

Instantly share code, notes, and snippets.

@erkattak
Created April 2, 2013 01:41
Show Gist options
  • Save erkattak/5289312 to your computer and use it in GitHub Desktop.
Save erkattak/5289312 to your computer and use it in GitHub Desktop.
Throw this in an initializer and you'll be able to display date/time strings however you want. Just pass object.date_field.to_s(:time_with_zone), etc.
Time::DATE_FORMATS.merge!(
datetime_military: '%Y-%m-%d %H:%M',
datetime: '%Y-%m-%d %I:%M%P',
time: '%l:%M%p',
time_with_zone: '%l:%M%p %Z',
time_military: '%H:%M%P',
datetime_short: '%m/%d %I:%M',
date: '%e',
day: '%a',
time_zone: '%Z',
date_time_long: '%A, %b %e %Y at %l:%M%p %Z',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment