python - Peewee 和 SQLite 返回错误的日期格式

标签 python sqlite flask peewee

我已经用 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 对象配合得很好。

关于python - Peewee 和 SQLite 返回错误的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50115624/

相关文章:

python - 在 Tkinter Gui 中创建框架类

android - SQLite 异常 : near/TABLE_NAME/: syntax error

sql - 在sqlite中查找最长的条纹

Python 时间日期匹配

python - 未定义错误: 'None' has no attribute 'user_id'

python - 如何创建处理多项式的函数?

python - 检查二维列表的索引并根据二维列表打印索引

python - static_url_path和变量规则

python - NGINX + Flask,没有 Gunicorn?

python - 将数据从 Flask 传递到 HTML