Last active
November 18, 2016 22:17
-
-
Save maxdanilov/1eb4953c99329e5eee6ea3691a47783c to your computer and use it in GitHub Desktop.
[Python] Datetime String to Epoch Time
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 calendar, datetime | |
import pandas as pd | |
date_str = '2016-01-01T00:00:00+01:00' | |
date = pd.to_datetime(date_str).tz_localize('UTC') | |
print calendar.timegm(date.timetuple()) # 1451602800 | |
# Using strftime('%s') is not recommended as it depends on the timezone of the machine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment