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?
UNIX timestamps are in second units.
end_timestamp = start_timestamp + 5 * 60 * 60
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With