在django的时间戳中添加2小时和1天 [英] Add 2 hours and 1 day onto a timestamp in django
本文介绍了在django的时间戳中添加2小时和1天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Game(models.Model):
pre>
starts = models.DateTimeField(auto_now_add = True)
ends = models.DateTimeField()
有没有人有这个解决方案?
解决方案
from datetime import timedelta
obj.starts + = timedelta(days = 1,hours = 2)
i have a model which holds data for a game, how would i add 2 hours and 1 day onto the 'starts' field?
class Game(models.Model): starts = models.DateTimeField(auto_now_add=True) ends = models.DateTimeField()
does anyone have a solution for this?
解决方案from datetime import timedelta obj.starts += timedelta(days=1, hours=2)
这篇关于在django的时间戳中添加2小时和1天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文