Skip to content

Instantly share code, notes, and snippets.

@n-at-han-k
Last active May 12, 2024 07:13
Show Gist options
  • Save n-at-han-k/25c1020c40a74247a930f3bb68d13482 to your computer and use it in GitHub Desktop.
Save n-at-han-k/25c1020c40a74247a930f3bb68d13482 to your computer and use it in GitHub Desktop.
Ruby strftime cheatsheet πŸ’Žβ°
# Additional reference here:
# https://strftime.org
require 'active_support/core_ext/integer/inflections' # To use .ordinalize() outside of rails
date = Time.now
date.strftime('%a %d %b %Y')
# => Sun 08 Sep 2024
date.strftime('%a %d %b %Y - %I:%M%p')
# => Sun 08 Sep 2024 - 03:40PM
date.strftime('%A %d %B %Y at %l:%M%P')
# => Sunday 08 March 2024 at 3:40pm
date.strftime('%d %b \'%y')
# => 08 Sep '24
date.strftime("%a #{date.day.ordinalize} %b")
# => Sun 8th Sep
date.strftime('%y-%m-%d')
# => 2024-09-08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment