time.asctime() method
time.asctime() method 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
Example: Converting tuple to time.struct_time object to string
This code uses the time
module to convert a specified timestamp (1627987508.6496193) into a human-readable date and time format using time.asctime()
. It does so both for the GMT (Greenwich Mean Time) timezone and the local timezone.
Python3
import time obj = time.gmtime( 1627987508.6496193 ) time_str = time.asctime(obj) print (time_str) obj = time.localtime( 1627987508.6496193 ) time_str = time.asctime(obj) print (time_str) |
Tue Aug 3 10:45:08 2021 Tue Aug 3 10:45:08 2021
Python Time Module
In this article, we will discuss the time module and various functions provided by this module with the help of good examples.
As the name suggests Python time module allows to work with time in Python. It allows functionality like getting the current time, pausing the Program from executing, etc. So before starting with this module, we need to import it.