【发布时间】:2014-01-11 17:35:03
【问题描述】:
我想将从我的 sqlite3 数据库中选择的日期时间转换为 unixepoch。我想,一种简单的方法是在 unixepoch 中的数据库中插入时间戳,但我宁愿不这样做,因为它会使我的数据库的可读性降低。
conn = sqlite3.connect('test.db')
c = conn.cursor()
c.execute('CREATE TABLE if not exists table_name (datetime text, column1 real, column2 real)')
cur.execute("INSERT INTO table_name VALUES (datetime(CURRENT_TIMESTAMP, 'localtime'),?,?)", data)
c.execute("SELECT datetime from table_name")
#here I would like to convert the above selection (datetime in localtime) to unixepoch
感谢您阅读本文!
【问题讨论】:
标签: python datetime sqlite epoch