Vinoth Mohan Vinoth Mohan - 2 years ago 184
Python Question

How to conver datetime to timestamp epoch

i am new to python 2.7, wondering and facing issue how to convert datetime to timestamp epoch.

Also the date time is in current UTC.
example :
2016-05-11 18:33:44 to 1462958071

Answer Source

Convert string to python datetime object and then parse the seconds

a ="2016-05-11 18:33:44"
b= datetime.strptime(a,"%Y-%d-%m %H:%M:%S")
print b.strftime('%s') # returns time in epoch
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download