Python 2.7のsqlite3 datetimeオブジェクトに奇妙な問題があります。この例を実行:sqlite3のPython datetimes
import sqlite3
import datetime
con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cur = con.cursor()
cur.execute("create table test(d date, ts timestamp)")
today = datetime.date.today()
now = datetime.datetime.now()
cur.execute("insert into test(d, ts) values (?, ?)", (today, now))
cur.execute("select d, ts from test")
row = cur.fetchone()
print today, "=>", row[0], type(row[0])
print now, "=>", row[1], type(row[1])
cur.execute('select current_date as "d [date]", current_timestamp as "ts [timestamp]"')
row = cur.fetchone()
print today, "=>", row[0], type(row[0])
print now, "=>", row[1], type(row[1])
が私にこの出力を与える:
2012-02-10 => 2012-02-10 <type 'datetime.date'>
2012-02-10 08:17:10.222291 => 2012-02-10 08:17:10.222291 <type 'datetime.datetime'>
2012-02-10 => 2012-02-09 <type 'datetime.date'>
2012-02-10 08:17:10.222291 => 2012-02-09 19:17:10 <type 'datetime.datetime'>
PARSE_COLNAMESメソッドを使用している場合retrived日時が間違っているようです。何故ですか?あなたはニュージーランドのタイムゾーン(UTC-12または夏時間とUTC-11が観察されている)であるように、この例では、あなたが示す出力からPython docs
これをクリアしてくれてありがとう、本当の頭の傷だった – pearpenguin