by 5/12/2005 12:49:00 PM 0 comments

Generating epoch seconds in python

I often need to convert a specific time to epoch seconds in various languages. Here's a python way:
# A date string to epoch seconds
epoch = time.mktime(time.strptime('1982-01-01 00:00:00', '%Y-%m-%d %H:%M:%S'))

# Epoch seconds to a date string
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epoch))

hohonuuli

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 comments: