【发布时间】:2017-02-21 19:38:19
【问题描述】:
我需要知道如何获取 edit_date(我的一个模型中的列)和 datetime.now() 之间经过的时间。我的 edit_date 列在 DateTimeField 格式下。 (我使用的是 Python 2.7 和 Django 1.10)
这是我想要做的功能:
def time_in_status(request):
for item in Reporteots.objects.exclude(edit_date__exact=None):
date_format = "%Y-%m-%d %H:%M:%S"
a = datetime.now()
b = item.edit_date
c = a - b
dif = divmod(c.days * 86400 + c.minute, 60)
days = str(dif)
print days
我从这个函数中得到的唯一信息是经过的分钟数和秒数。我需要的是按以下格式获取此日期:
Time_elapsed = 3d 47m 23s
有什么想法吗?如果我不清楚您是否需要更多信息,请告诉我
感谢您的关注,
【问题讨论】:
-
this 怎么样?
标签: django python-2.7 datetime time