Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'wiki': 0.03; 'output': 0.04; 'dependency': 0.07; 'python': 0.09; 'mentions': 0.09; 'objects.': 0.09; '2.7': 0.13; "hasn't": 0.15; '"working': 0.16; '2.7:': 0.16; "isn't.": 0.16; 'parser.': 0.16; 'subject:ISO': 0.16; 'subject:parser': 0.16; 'subject:where': 0.16; 'time"': 0.16; 'wrote:': 0.17; 'input': 0.18; 'module': 0.19; 'parse': 0.22; "i'd": 0.22; 'so.': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'skip:" 20': 0.26; "doesn't": 0.28; 'subject:/': 0.28; 'issues.': 0.29; 'url:python': 0.32; 'says': 0.33; 'dates': 0.33; 'point,': 0.33; 'to:addr :python-list': 0.33; 'skip:d 20': 0.34; 'updated': 0.34; 'third': 0.34; 'moved': 0.35; 'outstanding': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'method': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'easy': 0.60; 'john': 0.60; 'received:62': 0.62; 'dead': 0.62; 'from:addr:t': 0.84; 'received:62.75': 0.84 Date: Thu, 06 Sep 2012 21:44:13 +0200 From: Thomas Jollans User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Parsing ISO date/time strings - where did the parser go? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346961101 news.xs4all.nl 6885 [2001:888:2000:d::a6]:35473 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28632 On 09/06/2012 09:27 PM, John Nagle wrote: > In Python 2.7: > > I want to parse standard ISO date/time strings such as > > 2012-09-09T18:00:00-07:00 > > into Python "datetime" objects. The "datetime" object offers > an output method , datetimeobj.isoformat(), but not an input > parser. There ought to be > > classmethod datetime.fromisoformat(s) http://docs.python.org/library/datetime.html#datetime.datetime.strptime The ISO date/time format is dead simple and well-defined. strptime is quite suitable. > > but there isn't. I'd like to avoid adding a dependency on > a third party module like "dateutil". > > The "Working with time" section of the Python wiki is so > ancient it predates "datetime", and says so. > > There's an iso8601 module on PyPi, but it's abandoned; it hasn't been > updated since 2007 and has many outstanding issues. > > There are mentions of "xml.utils.iso8601.parse" in > various places, but the "xml" module that comes > with Python 2.7 doesn't have xml.utils. > > http://www.seehuhn.de/pages/pdate > says: > > "Unfortunately there is no easy way to parse full ISO 8601 dates using > the Python standard library." > > It looks like this was taken out of "xml" at some point, > but not moved into "datetime". > > John Nagle >