python - Misunderstood timezone conversion -
i'm converting datetime timezone (from europe/paris america/guadeloupe). result not expect:
import pytz import datetime tzinfo = pytz.timezone('europe/paris') datetime_with_timezone = datetime.datetime( 2000, 1, 1, 0, 0, 0, tzinfo=tzinfo ) print(datetime_with_timezone) new_tzinfo = pytz.timezone('america/guadeloupe') print(datetime_with_timezone.astimezone(new_tzinfo))
produces:
2000-01-01 00:00:00+00:09 1999-12-31 19:51:00-04:00
why datetime_with_timezone
contain +00:09
?
this seems known issue, according pytz documentation:
unfortunately using tzinfo argument of standard datetime constructors ‘’does not work’’ pytz many timezones.
the documentation provides further advice that
the preferred way of dealing times work in utc, converting localtime when generating output read humans.
Comments
Post a Comment