19

When using strftime @tzformat = "%F,%l:00 %p":

I want exactly one space between the comma and the hour. But %l gives no space for 10, 11 and 12 whereas if I put “ %l” I get two spaces for 0-9 (one from the padding and another from the space I add).

Month has no-padding option. I don’t see the same for hour.

What am I missing?

1
  • 1
    Show us your input data and the expected output along with an example of your code. Commented Jan 30, 2015 at 0:01

1 Answer 1

35

The - modifier removes padding. If you use %-l instead of %l it will not put a space at all, and you can manually add a space.

Time.now.strftime @tzformat = "%F, %-l:00 %p"            #=> "2015-01-29, 8:00 PM"
(Time.now + 3600*2).strftime @tzformat = "%F, %-l:00 %p" #=> "2015-01-29, 10:00 PM"
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.