strptime on Unix systems

Nathaniel Haas nate at hfd.com
Wed Dec 22 07:00:15 EST 1999


I'd personally recommend using Marc-André Lemburg's mxDateTime <http://starship.python.net/~lemburg/mxDateTime.html>.

For time zone support, use a DateTime intstance's .tz attribute.

Though I can't vouch for it's strptime on non-Unix platforms.


Nathaniel

Malcolm Tredinnick wrote:
> 
> On a Linux technical support mailing list I am on, somebody recently posted a
> question about Python and although I was able to answer it, the logic behind
> the answer has me stumped:
> 
> The following does *not* work under Linux (at least):
> 
> import time
> format = '%a %b %d %H:%M:%S %Z %Y'
> t = time.localtime(time.time())
> timestring = time.strftime(format, tt)          # Works OK
> timetuple = time.strptime(tt, format)           # Throws ValueError
> 
> The reason for this problem is that strftime and strptime are based on their
> C-library counterparts and according the man pages, while strftime does take a
> %Z modifier in the format string, strptime does NOT understand this modifier.
> (so you can remove the %Z from format and the above snippet is fine.)
> 
> Two questions:
> (1) What is the story on other Unix systems? Is this a general problem (I hope
> not)?
> 
> (2) Is there any logic hidden behind the fact that one direction takes %Z and
> the other does not?
> 
> Cheers,
> Malcolm Tredinnick
> 
> --
> Telepath required. You know where to apply...




More information about the Python-list mailing list