0

I'm returning information from an API and it uses this format to send timestamps, is there any easy way to return this time as Unix? It returns as a string and all the methods i've tried so far don't work. Thank you for any help

DreamLogic
  • 23
  • 5

1 Answers1

0

Let's say somehow you got the time as YYY-mm-ddTHH:MM:SS format.

To convert from string to a time object you can use:

from datetime import datetime

t = datetime.strptime("2021-11-4T10:44:00", "%Y-%m-%dT%H:%M:%S")

Now you have a datetime object which you can use to do as you wish. For example you want to convert it to unix time format (which @pyzer shared as a comment)?

t.timestamp()
MSH
  • 1,743
  • 2
  • 14
  • 22