strftime flags on Linux systems

If you want to get the numeric month from strftime your only only is %m which is zero padded. So January is “01”. But what if you don’t want zero padding? Turns out that’s non-trivial, unless you’re on a system that supports strftime flags. Then you can use “%-m” for no padding (“1”) and “%_m” for space padding (” 1″). These same flags work on all of the other formatters so you can use “%_d” for space padded day instead of having to remember to use “%e”. Not portable, but much more readable.

Leave a Reply

Your email address will not be published. Required fields are marked *