This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: time.ctime() uses %3d instead of %.2d to format.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder: Document time.ctime format
View: 13927
Assigned To: Nosy List: William Chaseling, martin.panter
Priority: normal Keywords:

Created on 2018-09-12 03:01 by William Chaseling, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg325114 - (view) Author: William Chaseling (William Chaseling) Date: 2018-09-12 03:01
time.ctime() returns _asctime from a C module.
_asctime returns a PyUnicode_FromFormat() result using "%s %s%3d %.2d:%.2d:%.2d %d" as the string formatter.

This works: 'Wed Sep 12 22:30:00 2018'
Except when day <10, because it uses %3d instead of %.2d
'Wed Sep  2 22:30:00 2018'

This seems like it might be intended behavior for some reason, but I don't see the reason.
msg325115 - (view) Author: William Chaseling (William Chaseling) Date: 2018-09-12 03:03
It's easy to get around using .replace('  ', ' '), but it's still a bit annoying.
msg325117 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-09-12 03:47
I think "ctime" and "asctime" are supposed to wrap or imitate the standard C functions: <https://port70.net/~nsz/c/c11/n1570.html#7.27.3.2>, so I think this is intended behaviour. But see Issue 13927 about improving the documentation.

For a single-digit day of the month, there is supposed to be two spaces. Using "%.2d" would produce "Sep02" or "Sep 02", with a leading zero. On the other hand, changing the double space to a single space would produce "Sep 2", without a leading zero.
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78823
2018-09-12 03:47:50martin.pantersetstatus: open -> closed

superseder: Document time.ctime format

nosy: + martin.panter
messages: + msg325117
resolution: not a bug
stage: resolved
2018-09-12 03:03:09William Chaselingsetmessages: + msg325115
2018-09-12 03:01:23William Chaselingcreate