Skip to content

Instantly share code, notes, and snippets.

@yiidtw
Created August 30, 2019 09:28
Show Gist options
  • Save yiidtw/be466f6df7dede6044c0b46c8ad5b9d5 to your computer and use it in GitHub Desktop.
Save yiidtw/be466f6df7dede6044c0b46c8ad5b9d5 to your computer and use it in GitHub Desktop.
convert UTC datetime in string to unix timestamp using python3
import datetime
import dateutil.parser # pip install python-dateutil
s = '2019-05-15T01:23:54Z'
d = dateutil.parser.parse(s)
t = d.replace(tzinfo=datetime.timezone.utc).timestamp()
# s = '2019-05-15T01:23:54Z'
# d = datetime.datetime(2019, 5, 15, 1, 23, 54, tzinfo=tzutc())
# t = 1557883434.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment