我需要将统计数据显示为数字



我刚开始学习django,遇到了一个问题当使用defstr(自我):返回self.timetable管理面板中的日期显示为数字,但它给出错误"str返回非字符串(类型为datetime.time) "当替换str时使用其他命令时,时间显示如下

需要格式化datetime。时间对象到字符串,像这样

from datetime import datetime
current = datetime.now().time()  # datetime.time object
string_time = current.strftime("%H:%M:%S")  # this value is what you need

如果需要,可以更改格式

https://docs.python.org/3/library/datetime.html strftime-and-strptime-behavior

最新更新