Search code examples
cstrftime

What is the difference between %h and %b in strftime


I was reading the man page for strftime(3) and I found this:

%b The abbreviated month name according to the current locale. (Calculated from tm_mon.)

[...]

%h Equivalent to %b. (SU)

Are both exactly the same or is there any difference? Is there a special case where one should be preferred over the other?


Solution

  • They are equivalent in behaviour. However, %h was standardized in the Single Unix Specification (SU). It is an addition that did not exist in C89.

    There is practically never a case where %h would work but %b would not - it would mean you're targeting a Unix system that supports %h but does not support %b with an implementation that conforms to neither the 31-year-old standard revision, nor any of its amendments. The opposite is still (unfortunately) more likely.

    TL;DR: always use %b instead of %h.