Created
August 30, 2019 09:28
-
-
Save yiidtw/be466f6df7dede6044c0b46c8ad5b9d5 to your computer and use it in GitHub Desktop.
convert UTC datetime in string to unix timestamp using python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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