Date.today.strftime('%b %d, %Y').gsub(/ 0(\d\D)/, ' \1')
Um... strike that. Seems %e does it without the extra work. Thanks Peter!
11381 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Date.today.strftime('%b %d, %Y').gsub(/ 0(\d\D)/, ' \1')
Date.today.strftime('%m/%d/%y').gsub( /0?(\d)\/0?(\d)\/(\d{2})/, '\1/\2/\3' )
08/03/07-01:30
8/3/07-1:30
Time.now.strftime('%m/%d/%y-%I:%M').gsub(/0?(\d)\/0?(\d)\/(\d{2})-0?(\d)/,'\1/\2/\3-\4')
"04/12/07".gsub(/0?(\d)\/0?(\d{1,2})\/(\d{2})/,'\1/\2/\3')
Time.now.strftime('%m/%d/%y-%I:%M').gsub(/0?(\d)\/0?(\d{1,2})\/(\d{2})-0?(\d)/,'\1/\2/\3-\4')
irb(main):001:0> t= Time.now => Sat Jan 05 17:39:00 -0500 2008 irb(main):002:0> t.strftime("%e") #Doesn't work => "" irb(main):003:0> t.strftime("%d") #Does work => "05"
Time.now.daydoes the trick. Doh.
You need to create an account or log in to post comments to this site.