如何在SQLite3中以人类可读的格式打印时间戳?

And*_*dré 0 python sqlite timestamp

我需要在SQLite中打印日期,如"24-03-2011 10:45:00",现在我只能打印日期.

>>> import sqlite3
>>> database = sqlite3.connect('basedadosteste.db')
>>> cursor = database.cursor()
>>> cursor.execute("SELECT date('now');")
<sqlite3.Cursor object at 0x00BC0710>
>>> results = cursor.fetchall()
>>> for entry in results:
...     print entry
...
(u'2011-03-25',)
>>>
Run Code Online (Sandbox Code Playgroud)

有人能给我一个如何做到这一点的线索吗?

最好的祝福,

Dan*_*man 5

date只给你日期,因此得名.如果你想要日期和时间,你必须使用datetime.

如果要格式化日期,可以strftime在SQL命令或Python中使用.请参阅sqlite3 date docs.

这可行:

SELECT strftime('%d-%m-%Y %H:%M:%S', 'now');
Run Code Online (Sandbox Code Playgroud)