datetime.ctime

The same layout as C's ctime() and asctime(), produced by Python itself — so it is identical on every platform and ignores the locale. Microseconds and the UTC offset are not shown.

date / datetime methodPython 2.3+Live demo
Common call
dt.ctime()
Returns
'Tue Sep 29 14:30:05 2026'
Replaces
time.asctime(dt.timetuple()) and strftime('%a %b %e %H:%M:%S %Y')
Watch out
Drops microseconds and the offset; not for storage
dt.ctime()
→ str

Demo

Live evaluation
Any date or timestamp in the fixed C layout. A date gets 00:00:00.
Try:
Inputs
whenstran ISO 8601 date or timestamp
Code
from datetime import datetime
datetime.fromisoformat('2026-09-29T14:30:05').ctime()
Result
'Tue Sep 29 14:30:05 2026'

The day of the month is padded with a space ("Sep 5"), the year with zeros ("0005"). The +05:00 offset and the milliseconds simply disappear.

Common patterns

Quick human-readable log line
Fine for debugging output; use isoformat for anything parsed later.
print(f'[{dt.ctime()}] job finished')

Examples

1. A datetime
from datetime import datetime datetime(2026, 9, 29, 14, 30, 5).ctime()
Returns
'Tue Sep 29 14:30:05 2026'
2. A date is midnight
from datetime import date date(2026, 9, 29).ctime()
Returns
'Tue Sep 29 00:00:00 2026'
3. Space-padded day
from datetime import datetime datetime(2026, 9, 5, 14, 30).ctime()
Returns
'Sat Sep 5 14:30:00 2026'
4. Always 24 characters
from datetime import datetime len(datetime(2026, 9, 5).ctime())
Returns
24

Pitfalls

1. Using ctime() output as data
The offset and microseconds are gone, so it cannot round-trip. Store isoformat() instead.
ctime()
from datetime import datetime, timedelta, timezone
datetime(2026, 9, 29, 14, 30, 5, 999, tzinfo=timezone(timedelta(hours=5))).ctime()
'Tue Sep 29 14:30:05 2026'
isoformat()
from datetime import datetime, timedelta, timezone
datetime(2026, 9, 29, 14, 30, 5, 999, tzinfo=timezone(timedelta(hours=5))).isoformat()
'2026-09-29T14:30:05.000999+05:00'

When to use

Use it
  • Debug output that should look like Unix date
  • Matching legacy asctime-formatted logs
Reach for something else
  • Storage and APIs → isoformat()
  • Localized display → strftime

Notes

CPython impl
format_ctime in Modules/_datetimemodule.c: "%s %s %2d %02d:%02d:%02d %04d" with English day and month names — no C library call
Parsing
datetime.strptime(s, '%a %b %d %H:%M:%S %Y') reads it back (%d accepts the space-padded day)

FAQ

No. The day and month names are hard-coded English abbreviations, unlike strftime("%c"), which follows the LC_TIME locale.