YouTip LogoYouTip

Python Str Timestamp

# Python3.x Python: Convert String Time to Timestamp [![Image 3: Document Object Reference](#) Python3 Examples](#) Given a string time, convert it to a timestamp. ## Example import time a1 = "2019-5-10 23:40:00"# First convert to a time array timeArray = time.strptime(a1, "%Y-%m-%d %H:%M:%S")# Convert to a timestamp timeStamp = int(time.mktime(timeArray))print(timeStamp)# Format conversion - convert to / a2 = "2019/5/10 23:40:00"# First convert to a time array, then convert to another format timeArray = time.strptime(a2, "%Y/%m/%d %H:%M:%S")otherStyleTime = time.strftime("%Y/%m/%d %H:%M:%S", timeArray)print(otherStyleTime) Executing the above code outputs the following: 15575028002019/05/10 23:40:00 [![Image 4: Document Object Reference](#) Python3 Examples](#)
← File CompareMethod Continue β†’