Python datetime.ctime() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
datetime method

Definition

ctime() returns the date and time in the classic C ctime() layout: weekday, month, day, time, and year, as in 'Fri Mar 15 10:30:45 2024'. The result is always 24 characters long.

Single-digit days are padded with a space, not a zero ('Sun Mar 3'). There are no options; for any other layout use strftime().

datetime.ctime() is an instance method of datetime.datetime: call it on an existing object with dot notation, such as moment.ctime(...). Import the class first, for example from datetime import datetime. The date class has a method with the same name.

Syntax

Call it with no arguments.

python
text = moment.ctime()
text = day.ctime()
CallWhat it does
datetime(2024, 3, 15, 10, 30, 45).ctime()Returns 'Fri Mar 15 10:30:45 2024'.
datetime(2024, 3, 3, 8, 5).ctime()Returns 'Sun Mar 3 08:05:00 2024': the day is space-padded.
date(2024, 3, 15).ctime()Returns 'Fri Mar 15 00:00:00 2024': a date shows midnight.

It matches time.ctime() output, so it is handy when imitating Unix log lines.

Method signatures
python
datetime.ctime()
date.ctime()
# returns: str like 'Fri Mar 15 10:30:45 2024'

Parameters

ctime() takes no parameters.

Return Value

Return ValueDescription
strA 24-character string in the form 'Www Mmm dd hh:mm:ss yyyy'.

Python Examples

Example 1 — See the ctime() Layout

Format a two-digit day, a one-digit day, and a plain date.

python
from datetime import date, datetime

print(datetime(2024, 3, 15, 10, 30, 45).ctime())
print(datetime(2024, 3, 3, 8, 5).ctime())
print(date(2024, 3, 15).ctime())

How It Works

  1. Fixed fields. Short weekday, short month, day, 24-hour time, then the year.
  2. Space padding. Day 3 is written as a space plus 3, so the columns still line up.
  3. Dates show midnight. A date has no clock, so the time part is 00:00:00.

Example 2 — Compare ctime() with a Similar strftime() Format

Rebuild the layout with strftime() and spot the one difference on a single-digit day. The %a and %b names assume the default C/English locale.

python
from datetime import datetime

moment = datetime(2025, 7, 4, 18, 0)
print(moment.ctime())
print(moment.strftime("%a %b %d %H:%M:%S %Y"))
print(moment.ctime() == moment.strftime("%a %b %d %H:%M:%S %Y"))
print(len(moment.ctime()))

How It Works

  1. Space vs zero. ctime() pads the 4 with a space; %d pads it with a zero.
  2. Not equal. That single character makes the strings different.
  3. Constant length. Thanks to the padding, the result is always 24 characters.

Example 3 — ctime() Ignores the Time Zone

Format an aware Tokyo time and the same instant in UTC.

python
from datetime import datetime, timedelta, timezone

tokyo = timezone(timedelta(hours=9))
moment = datetime(2024, 11, 30, 23, 15, tzinfo=tokyo)

print(moment.ctime())
print(moment.astimezone(timezone.utc).ctime())
print("+09" in moment.ctime())

How It Works

  1. Wall-clock only. ctime() formats the local fields 23:15 and drops the offset.
  2. Convert to change it. After astimezone(), the fields show the UTC reading 14:15.
  3. No zone text. The string never contains the offset, so add tzname() yourself if readers need it.

Frequently Asked Questions

A string like Fri Mar 15 10:30:45 2024: weekday, month, day, time, and year.
Days 1 to 9 are padded with a space instead of a zero, as in the C ctime() function.
No. Use strftime("%Z") or tzname() if you need it.
No. str() gives ISO style text such as 2024-03-15 10:30:45.
ctime() uses English abbreviations, matching the C ctime() layout, while strftime("%a") follows the current locale.

Next: datetime.date()

Return the date part of a datetime as a date object.

date() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful