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))

0 comments:
Post a Comment