I have a database containing dates formatted like: "2015-10-20 22:24:46". I need to convert these dates to UNIX timestamps (UTC), what's the easiest way to do it with Python?
Import the datetime library. Use the datetime. datetime class to handle date and time combinations. Use the strptime method to convert a string datetime to a object datetime.
import time
timestamp = time.mktime(time.strptime('2015-10-20 22:24:46', '%Y-%m-%d %H:%M:%S'))
For more on the format string with all the % symbols, see python's time library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With