Ruby strftime: Month without leading zero?

前端 未结 4 977
忘了有多久
忘了有多久 2021-01-30 15:57

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 hav

4条回答
  •  悲&欢浪女
    2021-01-30 16:23

    Some versions of strftime do allow prefixing with minus to format out leading zeros, for eg:

    strftime "%-d/%-m/%y"
    

    However this will depend on strftime on your system. So for consistency I would do something like this instead:

    dt = Time.local(2010, 'Sep', 1)
    printf "%d/%d/%d", dt.day, dt.month, dt.year
    

提交回复
热议问题