I noticed this when using 'date -f' to convert a date string: $ date -j -f '%b %j %T %Y %Z' 'Mar 18 12:00:00 2021 GMT' Mon Jan 18 12:00:00 GMT 2021 Passing this directly to strptime() gives the same results. If I do struct tm t; strptime("Mar 18 12:00:00 2021 GMT", "%b %j %T %Y %Z", &t); then t.tm_mon is always 0. If I use an invalid month then strptime() returns NULL, so it is recognising the month names, just not actually setting the correct month number in the struct tm. Tried with a couple of locales (including 'C') with the same results.
That's because you are using '%j' (day of the year) instead of '%d' (day of the month), and it overrides month specification as it comes earlier.
(In reply to Yuri Pankov from comment #1) Actually, "as it comes earlier" part is not correct; it seems to be implementation choice as standard does not specify was happens if conflicting specifiers are provided: - if %b and %j are specified, value converted by %b is ignored, month comes from %j - if %d and %j are specified, month day comes from %d, month comes from %j - if all of the %b, %d, and %j are specified, %j is ignored, values come from %b and %d
*** Bug 244906 has been marked as a duplicate of this bug. ***
Closing as "not a bug", please reopen with more information if you think otherwise.