Skip to content

Instantly share code, notes, and snippets.

@maxdanilov
Last active November 18, 2016 22:17
Show Gist options
  • Save maxdanilov/1eb4953c99329e5eee6ea3691a47783c to your computer and use it in GitHub Desktop.
Save maxdanilov/1eb4953c99329e5eee6ea3691a47783c to your computer and use it in GitHub Desktop.
[Python] Datetime String to Epoch Time
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