Convert time in string to UTF Timestamp in Python

Had to research various sources to come up with the solution that would convert a date/time in string format and convert it to UTC timestamp.

#!/usr/bin/python
import calendar, time, datetime

dt = '20150219000000'  #-- The time in format YYMMDDHHMMSS
print calendar.timegm(datetime.datetime.strptime(dt, '%Y%m%d%H%M%S').utctimetuple())  #-- Should get you 1424304000
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s