time module & ISO dates

Harald Hanche-Olsen hanche at math.ntnu.no
Tue Feb 1 10:32:57 EST 2000


+ Gerald Gutierrez <gutier at intergate.bc.ca>:

| Is there any way to get the standard Python time module to properly
| parse full ISO-8601 dates, such as "2000-01-31T22:07:43-0800"?
| strptime() ALMOST does what is needed but it does not provide for
| parsing the UTC offset at the end (the "-0800").

Apparently not, but mxDateTime contains a module ISO which seems to do
what you want.  If you don't want the whole module, you may be able to
extract the parts you do want.

| Also, does anyone know where I can get a list of standard timezone
| names as is understood by Python?

As far as I can tell, that depends on the underlying C implementation.
Relying on standard time zone names is in general not to be
recommended anyway, since there *is* no generally recognized standard,
except for UTC and its aliases GMT and Z.  (Beware of military
single-letter time zone names other than Z, as RFC 822 got them
backwards, rendering them useless for mail purposes.)  True, the time
zones of the continental US are standard for mail, but even for those
confusion is possible, as some take EDT to mean European daylight
time!  You are better off sticking to numerical time zone designators.

In particular, the time zone names on various Unix boxes are not to be
trusted.  They should be used merely as local conventions used to
manage local time zone information.

Sometimes I wonder if time zones are worth the bother.  Why not stick
to UTC for all purposes?  In my current time zone (-0400), I could get
up at 12:00 and go to bed at 04:00 and not feel guilty about it.

but-the-Japanase-might-see-it-differently-ly y'rs,
-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- "There arises from a bad and unapt formation of words
   a wonderful obstruction to the mind."  - Francis Bacon




More information about the Python-list mailing list