gpt4 book ai didi

python - 在 Web2py Python 中格式化日期

转载 作者:太空狗 更新时间:2023-10-30 01:55:18 24 4
gpt4 key购买 nike

我正在寻找一个函数来格式化日期以获得日、月和年。日期以以下格式 2012-09-26 存储在我的数据库中。

最佳答案

如果你的目标是在web2py模板上显示,那么你必须使用纯Python来格式化

{{=row.datetime_field.strftime("%d/%m/%Y")}}

以上将生成25/09/2012

看看 Python strftime 文档。

如果只想显示日期。

{{=row.datetime_field.date}}

您也可以将其设置为该字段的表示

db.mytable.datetime_field.represent = lambda value, row: value.strftime("format-here")

表示仅对 SQLFORM.grid 和 SQLTABLE 有用

你只需要strftime

关于python - 在 Web2py Python 中格式化日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12605934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com