我从 PostgreSQL 获得了一条记录,它的类型是timestamp without time zone
我正在使用 psycopg2
如果我datetime
使用timestamp with time zone
. 但是,目前情况并非如此。
http://initd.org/psycopg/docs/usage.html#time-zones-handling
我意识到我正在获得浮点类型。
我怎么能假设从给定的浮点数中获得价值?
Jan 07, 2010
16:38:49
connection.cursor.execute(sql, data)
records = connection.cursor.fetchall()
# In PostgreSQL, type is "timestamp without time zone"
# <type 'float'>
print type(record['_start_timestamp'])
# 1.28946608161e+12
print record['_start_timestamp']
# TypeError: argument must be 9-item sequence, not float
print time.strftime("%a, %d %b %Y %H:%M:%S +0000", record['_start_timestamp'])