No spaces in hours in strftime

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

I want exactly one space between the comma and the hour. But %l does not give spaces for 10, 11 and 12, whereas if I put " %l" , I get two spaces for 0-9 (one from the complement and the other from the added space).

The month has no fill option. I do not see the same for an hour.

What am I missing?

+6
source share
1 answer

The modifier removes the indentation. If you use% -l instead of% l, it will not put free space, 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" 
+13
source

Source: https://habr.com/ru/post/981738/


All Articles