【问题标题】:How to subtract these two dates? How to count the number of minutes between them?如何减去这两个日期?如何计算他们之间的分钟数?
【发布时间】:2013-07-05 16:16:30
【问题描述】:
when_start = models.DateTimeField()
when_end = models.DateTimeField()

如何获得when_startwhen_end 之间的分钟差?

my_minutes = when_end - when_start = #number of minutes

【问题讨论】:

    标签: python django datetime python-datetime


    【解决方案1】:

    当你减去时,你会得到这样的东西:

    datetime.timedelta(0, 5, 41038)
    

    将其转换为分钟:

    minutes = (when_end - when_start).total_seconds()/60
    

    【讨论】:

    • 谢谢。我有这个错误:'datetime.timedelta' object has no attribute 'total_secounds'
    【解决方案2】:

    我愿意

    my_minutes = (when_end - when_start).total_seconds() / 60
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 2017-08-03
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多