Python asctime()

tukesh_'s avatar
Published Oct 30, 2025
Contribute to Docs

The time.asctime() Python function converts a time value (a 9‑element tuple or time.struct_time) into a readable, 24‑character string such as 'Wed Sep 17 19:40:37 2025'.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

Syntax of time.asctime()

import time

time.asctime(t)

Parameters:

  • t (optional): A 9‑tuple or time.struct_time representing a UTC or local time, with fields (year, month, mday, hour, min, sec, wday, yday, isdst) as produced by time.localtime() or time.gmtime().
    • If omitted, time.asctime() uses time.localtime().
    • wday (weekday) and yday (day of year) are ignored.
    • isdst may be -1, 0, or 1.

Return value:

  • str: A 24‑character string of the form 'Sun Jun 20 23:21:05 1993'. The day of month is two characters wide and space‑padded if needed (e.g., 'Wed Sep 17 19:40:37 2025').

Example

Convert the current local time (from localtime()) and show the default call with no arguments:

import time
# Using localtime() with asctime()
t = time.localtime()
lc = time.asctime(t)
print("Current local time represented in string:", lc)
# Default call (formats current local time)
print(time.asctime())

Example output:

Current local time represented in string: Wed Sep 17 19:40:37 2025
Wed Sep 17 19:40:37 2025

Note: The exact output will vary depending on when the function is run.

Codebyte

Run this to see time.asctime() in action with local time, a UTC struct_time, and a custom tuple:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours