问题
I need to add 5 hours to a certain unix time stamp. Its like start and stop time for a game. So I have the knowledge of start time and the duration of the game. I need to put end time. How this can be done in python?
回答1:
UNIX timestamps are in second units.
end_timestamp = start_timestamp + 5 * 60 * 60
回答2:
Could be explicit and work with the following:
>>> from datetime import timedelta, datetime
>>> a = datetime.fromtimestamp(0)
>>> b = a + timedelta(hours=5)
>>> c = time.mktime(b.timetuple())
>>> c
18000.0
>>> datetime.fromtimestamp(c)
datetime.datetime(1970, 1, 1, 6, 0)
来源:https://stackoverflow.com/questions/13924124/adding-hours-to-unix-time-stamp-in-python