How to convert this string to Unix time? t = '20160224122738'
I can write a function to do this, but wanted to know if there was an already-existing simple method that I could use.
How to convert this string to Unix time? t = '20160224122738'
I can write a function to do this, but wanted to know if there was an already-existing simple method that I could use.
An easy way that comes to mind would be:
>>> import time
>>> import datetime
>>> t = '20160224122738'
>>> time.mktime(datetime.datetime.strptime(t, "%Y%m%d%H%M%S").timetuple())
1456309658.0
Try this,
>>> import datetime
>>> t = '20160224122738'
>>> int(datetime.datetime.strptime(t, '%Y%m%d%H%M%S').strftime("%s"))
1456297058