在Web2py Python中格式化日期 [英] Formatting date in Web2py Python

查看:198
本文介绍了在Web2py Python中格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for a function to format a date in order to get day, month and year. Dates are being stored in my database in the following format 2012-09-26.

推荐答案

如果你的目标是在web2py模板,因此您必须使用纯Python格式

If your goal is to display on web2py template, so you have to use pure Python to format

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

上面将会生成 25 / 2012

了解Python strftime文档。

Tale a look at Python strftime documentations.

{{=row.datetime_field.date}}

此外,您还可以将其设置为该字段的表示形式。

Also you can set it as a representation for that field

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

这个表示只对SQLFORM.grid和SQLTABLE有用

The representation will be useful only on SQLFORM.grid and SQLTABLE

所有你需要的是 strftime

这篇关于在Web2py Python中格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆