Convert string to timestamp Python

In this Python string tutorial, you will learn how to convert string to the timestamp in Python.

# Import the required modules
import time
import datetime

# Create a string
S = "2022-10-25"

# Convert string into timestamp
T = time.mktime(datetime.datetime.strptime(S, "%Y-%m-%d").timetuple())

# Print timestamp
print(T)

Output:

1666638000.0

Free learning resources: AiHintsCodeAllow

Leave a Comment

Your email address will not be published.