Title: Incorrect documentation for strftime()/strptime() format code %f
Type: behavior Stage:
Components: Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fdrake, josh.r, jujuwoman, p-ganssle
Priority: normal Keywords:

Created on 2018-04-29 01:06 by jujuwoman, last changed 2018-10-12 18:06 by fdrake.

File name Uploaded Description Edit
Bug jujuwoman, 2018-04-29 01:06 MWE of the bug
Messages (3)
msg315873 - (view) Author: Judy Wang (jujuwoman) * Date: 2018-04-29 01:06
According to, %f is zero-padded on the left. But actual Python 3 behavior is puts the zero padding on the right.
msg316110 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2018-05-03 04:41
Note: strftime follows the existing documentation:

>>> datetime.datetime(1970, 1, 1, microsecond=1).strftime('%f')

The strptime behavior bug seems like a duplicate of #32267, which claims to be fixed in master as of early January; may not have made it into a release yet though. I can't figure out how to view the patch on that issue, it doesn't seem to be linked to GitHub like normal.
msg321106 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2018-07-05 15:29
I don't believe this is a duplicate if #32267, which is actually about the %z directive.

I think the implementation here is correct and the documentation is semi-correct, it depends on how you look at it, consider:

>>> datetime(2018, 1, 1, 0, 0, 0, 1).strftime('%f')

>>> datetime(2018, 1, 1, 0, 0, 0, 100000).strftime('%f')

In the first case "1" got expanded to "000001" and "100000" was printed as-is. However, when you interpret it as being *after* the decimal point, you would consider the first one to not be zero-padded at all and the second one to be zero-padded on the right.

I think the documentation can just be changed to "zero-padded to 6 digits" without specifying left or right.
Date User Action Args
2018-10-12 18:06:22fdrakesetnosy: + fdrake
2018-07-05 15:29:42p-gansslesetmessages: + msg321106
2018-07-05 15:15:38p-gansslesetnosy: + p-ganssle
2018-05-03 04:41:09josh.rsetnosy: + josh.r
messages: + msg316110
2018-04-29 01:06:18jujuwomancreate