Last active
May 12, 2024 07:13
-
-
Save n-at-han-k/25c1020c40a74247a930f3bb68d13482 to your computer and use it in GitHub Desktop.
Ruby strftime cheatsheet πβ°
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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