Format timedelta to string

后端 未结 28 1670
春和景丽
春和景丽 2020-11-22 03:57

I\'m having trouble formatting a datetime.timedelta object.

Here\'s what I\'m trying to do: I have a list of objects and one of the members of the cl

28条回答
  •  隐瞒了意图╮
    2020-11-22 04:26

    My datetime.timedelta objects went greater than a day. So here is a further problem. All the discussion above assumes less than a day. A timedelta is actually a tuple of days, seconds and microseconds. The above discussion should use td.seconds as joe did, but if you have days it is NOT included in the seconds value.

    I am getting a span of time between 2 datetimes and printing days and hours.

    span = currentdt - previousdt
    print '%d,%d\n' % (span.days,span.seconds/3600)
    

提交回复
热议问题