The server sends a string that I striptime
and keep in a variable called here time_from_frontend
and then add a tzinfo like this:
import pytz
my_timezone = pytz.timezone("America/Guayaquil")
A = time_from_frontend.replace(tzinfo=my_timezone)
print A
print A.tzinfo
B = (datetime.datetime.today()).replace(tzinfo=my_timezone)
print B
print B.tzinfo
print B - A
Why do I get a huge difference between A and B? Here is what the terminal prints:
2016-02-11 20:00:00-05:19
America/Guayaquil
2016-02-12 01:08:35.478507-05:19
America/Guayaquil
5:08:35.478507
The frontend is sending me the actual time, when I do datetime.today()
and then specify the timezone, I thought I was gonna get a tiny difference between the A time and the B time (i.e microseconds), but I get 5 hours. which is the timezone difference ("America/Guayaquil" is GMT-5).
I kind of understand the error. But how can I solve it? is there a way to create a datetime.today()
object that corresponds to the local time?