VOOZH about

URL: https://www.geeksforgeeks.org/python/python-time-asctime-method/

⇱ Python | time.asctime() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | time.asctime() method

Last Updated : 12 Oct, 2021

Python time method time.asctime() is used to convert a tuple or a time.struct_time object representing a time as returned by time.gmtime() or time.localtime() method to a string of the following form:

Day Mon Date Hour:Min:Sec Year
For example:
Thu 08 22 10:46:56 2019

Python time asctime() Syntax:

time.asctime([t])

Python time asctime() Parameter: 

t (optional): A tuple or time.struct_time object representing a time as returned by time.gmtime() or time.localtime() method . If the 't' parameter is not provided or None then the current time as returned by time.localtime() method is used.

Python time asctime() Return type:

This method returns an string of the form Day Mon Date Hour:Min:Sec Year 

Example of Python time asctime()

Example 1: Use of time.asctime() method 

Output:

time.struct_time object as returned by time.gmtime() method:

time.struct_time(tm_year=2021, tm_mon=10, tm_mday=7, tm_hour=15, tm_min=30, tm_sec=51, tm_wday=3, tm_yday=280, tm_isdst=0)

time.struct_time obj in string of the form 'Day Mon Date Hour:Min:Sec Year':

Thu Oct  7 15:30:51 2021

time.struct_time object as returned by time.localtime() method:

time.struct_time(tm_year=2021, tm_mon=10, tm_mday=7, tm_hour=21, tm_min=0, tm_sec=51, tm_wday=3, tm_yday=280, tm_isdst=0)

time.struct_time obj in string of the form 'Day Mon Date Hour:Min:Sec Year':

Thu Oct  7 21:00:51 2021

Example 2: If the parameter 't' is not provided 

Output:

Thu Oct 7 21:01:45 2021

Example 3: If the parameter 't' is a tuple 

Output:

Thu Aug 22 11:21:48 2019
Comment
Article Tags: