Title: Document time.ctime format
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.8, Python 3.7, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Roger.Caldwell, eric.smith, georg.brandl, harman786, r.david.murray, vstinner, ztane
Priority: normal Keywords: patch

Created on 2012-02-02 20:49 by Roger.Caldwell, last changed 2019-01-04 23:19 by vstinner.

File name Uploaded Description Edit
ctime-doc.patch harman786, 2016-10-13 11:12 patch file review
Pull Requests
URL Status Linked Edit
PR 11303 open harman786, 2018-12-24 09:07
Messages (9)
msg152475 - (view) Author: Roger Caldwell (Roger.Caldwell) Date: 2012-02-02 20:49
Hi.  I found this today and thought I would report.  I could not find anywhere that it was expected behavior.  When using time.ctime() to convert a date which only has 1 digit in the day position it returs a string with 2 spaces after the month vs one.

In [2]: import os,time

In [3]: time.ctime(os.path.getmtime('file.cfg'))
Out[3]: 'Tue Dec 13 18:52:58 2011'

In [4]: time.ctime(os.path.getmtime('14d-1.log'))
Out[4]: 'Tue Feb  1 19:53:11 2011'

Is this expected behavior?
msg152483 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-02-02 22:29
That's definitely the expected behavior. It's the same as the C library version of ctime().

But I couldn't find it documented in the Python docs, so I'm changing this to a documentation issue.

Thanks for the report.
msg152496 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-02-03 07:10
asctime() docs say it's a 24 char string.
msg153310 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-02-14 00:23
> asctime() docs say it's a 24 char string.

I'm not sure that all platform conform to this "specification"... which is not future proof!

$ ./python 
Python 3.3.0a0 (default:af1a9508f7fa, Feb 14 2012, 01:18:15) 
[GCC 4.6.2 20111027 (Red Hat 4.6.2-1)] on linux
>>> import time
>>> time.ctime(2**38)
'Wed Jul 14 08:09:04 10680'
>>> len(time.ctime(2**38))

I suppose that you can say that the month day is formatted as 2 characters (padded with a space if needed).
msg153311 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-02-14 00:25
Or you could give the strftime specification string that produces the equivalent output.
msg278557 - (view) Author: Harmandeep Singh (harman786) * Date: 2016-10-13 11:12
I was bored, I generated a patch for this.

Hope this helps :)
msg332336 - (view) Author: Antti Haapala (ztane) * Date: 2018-12-22 08:32
This should be added to `asctime` too.

The space-padded behaviour complies with the C standard which was the intent - after all, before it was using C `asctime` directly, and says that unlike C asctime, it doesn't have the newline character, meaning that as a rule, it should then behave similar to it, and only exception is marked.

Unfortunately MSVC asctime has been incorrectly using leading zeros (
msg332422 - (view) Author: Harmandeep Singh (harman786) * Date: 2018-12-24 09:07
I have created the PR as mentioned, I have added the example for time.ctime() and also added the note to time.asctime.
msg332584 - (view) Author: Harmandeep Singh (harman786) * Date: 2018-12-27 11:08
I have created a PR for the patch that I submitted, as this is my first contribution to the docs, I need to know that how do we decide if a change has to make an entry to `Misc/NEWS.d/next/` or needs `skip news` tag?
Date User Action Args
2019-01-04 23:19:25vstinnersettitle: Extra spaces in the output of time.ctime -> Document time.ctime format
versions: - Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
2018-12-27 11:08:41harman786setnosy: - docs@python
messages: + msg332584
2018-12-24 09:07:15harman786setversions: + Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
stage: patch review
messages: + msg332422
pull_requests: + pull_request10527
2018-12-22 08:32:44ztanesetnosy: + ztane
messages: + msg332336
2018-09-12 03:47:50martin.panterlinkissue34642 superseder
2016-10-13 11:16:02harman786sethgrepos: - hgrepo360
2016-10-13 11:12:50harman786setfiles: + ctime-doc.patch

nosy: + harman786
messages: + msg278557

hgrepos: + hgrepo360
keywords: + patch
2012-02-14 00:25:56r.david.murraysetnosy: + r.david.murray
messages: + msg153311
2012-02-14 00:23:26vstinnersetnosy: + vstinner
messages: + msg153310
2012-02-03 07:10:51georg.brandlsetnosy: + georg.brandl
messages: + msg152496
2012-02-02 22:29:28eric.smithsetversions: + Python 3.2, Python 3.3
nosy: + docs@python, eric.smith

messages: + msg152483

assignee: docs@python
components: + Documentation, - None
2012-02-02 20:49:35Roger.Caldwellcreate