Ruby strftime: Month without leading zero?

Viewed 45127

Does Ruby's strftime have a format for the month without a leading zero?

I found %e for getting the day without the leading zero, but not having any luck with the month.

Ultimately wanting a date formatted like: 9/1/2010

4 Answers

Docs show a number of different options for configuring number format. Adding to the %-d format, you can also use these flags in place of "-":

Flags:
  -  don't pad a numerical output.
  _  use spaces for padding.
  0  use zeros for padding.
  ^  upcase the result string.
  #  change case.
  :  use colons for %z.

I had a similar problem and fixed it by converting strftime("%m") into an integer.

For example:

strftime("%m")+0 give the current month as integer 'without leading zero'

Simple, though not elegant.

Related