(python2.7.13)
要 $ pip install python-dateutil
In [1]: from datetime import datetime In [4]: expires_sec = 604799 # second In [5]: expires_sec * 1.0 / 60 / 60 Out[5]: 167.99972222222223 # hour (約7日) In [6]: from math import floor In [7]: floor(expires_sec * 1.0 / 60 / 60) # 切り捨て Out[7]: 167.0 In [8]: from dateutil.relativedelta import relativedelta In [9]: created_at = datetime.now() In [10]: created_at Out[10]: datetime.datetime(2017, 12, 13, 12, 5, 11, 937429) In [11]: from dateutil.relativedelta import relativedelta In [13]: created_at + relativedelta(hours=+167.0) Out[13]: datetime.datetime(2017, 12, 20, 11, 5, 11, 937429)