Peewee 和 SQLite 返回不正确的日期格式

Peewee and SQLite returning incorrect date format

我在 Python 和 Flask 中构建了一个 Web 应用程序,但无法从我的 SQLite 数据库中提取日期和时间。

我使用以下行将日期输入到数据库中-
order.order_placed = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

在我当前的示例中,将以下内容输入到数据库中 -
2018-05-01 12:08:49

但是当我调用 order.order_placed 我得到 datetime.date(2018, 5, 1)

即使我调用 str(order.order_placed) 我也会得到 '2018-05-01'

谁能帮我从数据库中获取完整的日期和时间?谢谢!

您可能正在使用 DateField,而实际上您想使用 DateTimeField

此外,您不需要在存储数据之前调用strftime。 Peewee 与 Python datetime 对象配合得很好。