pytz and timezone specialists

manatlan manatlan at gmail.com
Mon Dec 8 08:15:55 EST 2008


On 5 déc, 20:46, Ned Deily <n... at acm.org> wrote:
> In article
> <1f6172c1-4f70-42ea-8010-b72beb0af... at w24g2000prd.googlegroups.com>,
>
>
>
>  manatlan <manat... at gmail.com> wrote:
> > Here is a really simple code :
> > -------------------------------------------------------
> > from datetime import datetime
> > frompytzimport timezone
>
> > tz=timezone("Europe/Paris")
>
> > d=datetime(2008,12,12,19,00,00,tzinfo=tz)
> > print d.isoformat()
>
> > d=datetime.now(tz)
> > print d.isoformat()
> > -------------------------------------------------------
> > when I run it, it displays (according current time ;-):
>
> > 2008-12-12T19:00:00+00:09
> > 2008-12-05T19:15:38.135467+01:00
>
> > The Europe/Paris timezone is GMT+1 ... the second date seems to be
> > right (+01:00 at the end)
>
> > But why the first date ends with "+00:09" ?!? it should be +01:00 ...
> > no ?!
> > Where's the bug ?!? (sure : it's me ;-) ... but i don't understand
> > this simple thing)
> >>> tz = timezone("Europe/Paris")
> >>> d = tz.localize(datetime(2008,12,12,19,00,00))
> >>> print d.isoformat()
>
> 2008-12-12T19:00:00+01:00
>
> <http://pytz.sourceforge.net/>
>
> "This library only supports two ways of building a localized time. The
> first is to use the .localize() method provided by thepytzlibrary.
> This is used to localize a naive datetime (datetime with no timezone
> information).  ... Unfortunately using the tzinfo argument of the
> standard datetime constructors ''does not work'' withpytzfor many
> timezones."
>
> --
>  Ned Deily,
>  n... at acm.org

now, I use :
d=datetime.now(tz).replace(2008,12,12,19,00,00)

and it works like expected ...

btw, thanks for your answer



More information about the Python-list mailing list