I figured it out.

 I should be using pytz localize function and not passing tzinfo to
datetime.
WRONG: local_dt = datetime
(dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,tzinfo=local_timezone)
RIGHT:local_dt = local_timezone.localize(datetime
(dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second))

On Sep 5, 2:47 pm, zweb <traderash...@gmail.com> wrote:
> Converting from local to utc:
>
> local Timzone: America/Los_Angeles
> local_dt 2009-09-17 00:00:00-08:00
> utc_dt 2009-09-17 08:00:00+00:00 ( after converting from local to utc)
>
> when I convert back from UTC to America/Los_Angeles, I get back
> local_dt 2009-09-24 01:00:00
>
> which is one hour from where I started. Any clues how to fix it?
>
> My code below:
>
> From Local to UTC:
>     local_timezone = timezone(local_tz)
>     local_dt = datetime
> (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,
> tzinfo=local_timezone)
>     utc_dt = utc.normalize(local_dt.astimezone(pytz.utc))
>
> From UTC to Local:
>     utc_dt = datetime
> (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second, tzinfo=pytz.utc)
>     local_tz1 = timezone(local_tz)
>     loc_dt = local_tz1.normalize(utc_dt.astimezone(timezone(local_tz)))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to