I am using Heroku to run some python code.
The code that i have written uses a predefined time like example: 16:00 and compares that with the current time and the calculates the difference like this:
now = datetime.datetime.now()
starttime = datetime.datetime.combine(datetime.date.today(), datetime.time(int(hour), int(minute)))
dif = now - starttime
Running this locally ofc uses the time in my system i guess and everything is correct. However when i post it on the server and run it there the time is one hour back. So how can i fix this so it always uses the timezone that i am in?
I live in Sweden
Thank you all, Code examples would be deeply appreciated.
EDIT1
Rest of the code looks like this:
if dif < datetime.timedelta(seconds=0):
hmm = 3
elif dif < datetime.timedelta(seconds=45*60):
t = dif.total_seconds() / 60
time, trash = str(t).split(".")
time = time+"'"
elif dif < datetime.timedelta(seconds=48*60):
time = "45'"
elif dif < datetime.timedelta(seconds=58*60):
time = "HT"
elif dif < datetime.timedelta(seconds=103*60):
t = (dif.total_seconds() - 840) / 60
time, trash = str(t).split(".")
time = time+"'"
elif dif < datetime.timedelta(seconds=108*60):
time = "90'"
else:
time = "FT"
and using the imports that you provided i get this error now:
AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
i tried to do like this but it did not help:
from datetime import datetime, time, timedelta