[Zope] DateTime strftime problem

Ron Bickers rbickers-list-zope2 at logicetc.com
Mon Nov 7 12:15:53 EST 2005


On Mon November 7 2005 08:21 am, Jürgen Herrmann wrote:

> DateTime('2005/04/03 02:01 GMT').toZone('GMT-4')
>
> prints:
> 2005/04/02 22:01:00 GMT-4
> ...which is what i expected
> ---------------------------------------------------------------------
> DateTime('2005/04/03 02:01 GMT').toZone('GMT-4')\
> .strftime('%Y/%m/%d %H:%M %Z')
>
> prints:
> 2005/04/03 04:01
>
> hmm, where's the timezone information gone? to make it short, how
> can i get a text representation of a DateTime object in a given
> timezone?

strftime() timezone is broken in all versions of Zope that I know of.  You 
can work around it by using the individual functions to get the information.  
For example (not verified):

  dt = DateTime('2005/04/03 02:01 GMT').toZone('GMT-4')
  '%s/%s/%s %s:%s %s' % (dt.year(), dt.month(), dt.day(),
                         dt.hour(), dt.minute, dt.timezone())

or, if you throw the seconds in there and you keep them in the same order, 
you can just use parts():

  '%s/%s/%s %s:%s:%s %s' % (dt.parts())

-- 
Ron


More information about the Zope mailing list