在django的时间戳中添加2小时和1天 [英] Add 2 hours and 1 day onto a timestamp in django

查看:150
本文介绍了在django的时间戳中添加2小时和1天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拥有游戏数据的模型,我将如何在开始字段中添加2个小时和1天?

  class Game(models.Model):
starts = models.DateTimeField(auto_now_add = True)
ends = models.DateTimeField()
pre>

有没有人有这个解决方案?

解决方案

  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屋!

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