Red Squirrel Stumblog RSS

Dave Hoover stumbles through technology

Dec
30th
Tue
permalink

If you want Ruby’s strftime to give you single digit hours

Then the undocumented %l (yes, a lower-case L) is your friend.

Time.now.strftime("%I:%M%p")
# generates 05:00pm
Time.now.strftime("%l:%M%p")
# generates 5:00pm
That’s just evil that l looks so much like I.