0

How to add hours to a timestamp in python?

I have a timestamp in UTC, and I want to add hours to it. If I convert it to DateTime, it changes to local time. So, I want to add hours directly to the timestamp without converting to datetime.

import time
from datetime import datetime, timedelta

input = datetime(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day)
today = datetime.now()
days = (today - input).days
d = datetime(year=today.year, month=today.month, day=today.day) - timedelta(seconds=time.timezone) - timedelta(days=days)
utc_midnight_timestamp = int(time.mktime(d.utctimetuple()))

Now I want to keep adding 1 hour to the utc_midnight_timestamp many times

for x in range(1,24):
   #Need to keep incrementing utc_midnight_timestamp by x hours
   #use timestamp later

0 Answers0