Hi,
I have the following settings:
TIME_ZONE = 'UTC'
USE_TZ = True
I have a form allowing the user to put year, month, day, hour, minute and his timezone. I'm trying to convert the user date and time into UTC date and time
view.py
from dateutil import tz
dayf = form.cleaned_data['dayf']
monthf = form.cleaned_data['monthf']
yearf = form.cleaned_data['yearf']
hourf = form.cleaned_data['hourf']
minutef = form.cleaned_data['minutef']
timezonef = form.cleaned_data['timezonef']
from_zone = tz.gettz(timezonef)
to_zone = tz.gettz('UTC')
time_event_user = datetime.datetime(int(yearf), int(monthf), int(dayf), int(hourf), int(minutef))
time_event_user = time_event_user.replace(tzinfo=from_zone)
time_event_utc = time_event_user.astimezone(to_zone)
Now if I put timezone "Europe/Berlin" and today 8pm I will get both for time_event_user and time_eevnt_utc 7pm What's wrong here? Why is
time_event_user = time_event_user.replace(tzinfo=from_zone)
not working properly?