time.strftime()

Mikael Schönenberg micke at strakt.com
Mon Mar 10 06:51:43 EST 2003


On Mon, 10 Mar 2003, jsaul wrote:

> I have a problem when using time.strftime() to compose a RFC822
> date, namely the printed time zone is incorrect:
>
> >>> time.strftime("%a, %d %b %Y %H:%M:%S %z", time.localtime())
> 'Mon, 10 Mar 2003 10:26:51 +0000'
>
> It should be '+0100' because this is CET time zone:
> >>> time.strftime("%Z",time.localtime())
> 'CET'
>
> >>> time.timezone
> -3600
> >>> time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime())
> 'Mon, 10 Mar 2003 09:26:54 +0000'
>
> This is all correct. But I don't want to go via 'time.timezone'
> to get the proper offset into the date string. Unless the above
> behaviour is a bug, I must have overlooked something, but what?

It seems likely that what you've overlooked is this:

"The use of %Z is now deprecated, but the %z escape that expands to the
 preferred hour/minute offset is not supported by all ANSI C libraries."

From: http://python.org/doc/current/lib/module-time.html#foot18650

Not what you were hoping for, I'm sure, but probably the cause of your
problem. As to the solution... I can't think of any, apart from 'do it
yourself' :-(

/micke






More information about the Python-list mailing list