我获得PostgreSQL的记录,这类型为timestamp without time zone
psycopg2处理时间戳没有时区
我使用的psycopg2
如果我使用timestamp with time zone
我可能会datetime
对象。但是,目前情况并非如此。 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'])
太棒了!谢谢! – 2010-11-12 01:44:20