Python time Module Cheat Sheet
1. Importing
import time
2. Time Representations
# Epoch Time (Unix timestamp)
[Link]() # float: current time in seconds since epoch
# Structured Time (time.struct_time)
[Link]() # Local time as struct_time
[Link]() # UTC time as struct_time
3. Formatting & Parsing
# Convert struct_time to string
[Link]("%Y-%m-%d %H:%M:%S", [Link]())
# Convert string to struct_time
[Link]("2025-05-05", "%Y-%m-%d")
4. Sleep / Delay
[Link](5) # Pause for 5 seconds
5. Conversions
# struct_time to timestamp
[Link]([Link]())
# Timestamp to struct_time
[Link](1680000000)
6. Time Constants
[Link] # Offset of local (non-DST) timezone, in seconds west of UTC
[Link] # Offset during DST
[Link] # 1 if DST is defined, 0 otherwise
7. High-Resolution Timer
start = time.perf_counter()
# some code
end = time.perf_counter()
print(f"Elapsed: {end - start} seconds")