Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76083

Re: converting ISO8601 date and time string representations to datetime

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'package,': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'elegant': 0.07; 'string': 0.09; 'lawrence': 0.09; 'method,': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'language.': 0.14; 'argument,': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'valueerror': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'header:User-Agent:1': 0.23; 'format,': 0.24; 'parse': 0.24; 'specify': 0.24; 'stick': 0.24; 'string,': 0.24; "haven't": 0.24; "i've": 0.25; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; "i'm": 0.30; 'this.': 0.32; 'another': 0.32; 'subject:time': 0.33; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'convert': 0.35; 'but': 0.35; 'there': 0.35; 'dates': 0.36; 'representing': 0.36; 'hi,': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'catch': 0.60; 'full': 0.61; "you're": 0.61; 'times': 0.62; 'myself': 0.63; 'our': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; 'here': 0.66
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: converting ISO8601 date and time string representations to datetime
Date Mon, 11 Aug 2014 23:54:20 +0100
References <lrd185$tt3$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-180-173.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0
In-Reply-To <lrd185$tt3$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12869.1407797674.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407797674 news.xs4all.nl 2846 [2001:888:2000:d::a6]:36271
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76083

Show key headers only | View raw


On 31/07/2014 10:11, Wolfgang Maier wrote:
> Hi,
> I'm trying to convert ISO8601-compliant strings representing dates or
> dates and times into datetime.datetime objects.
> I tried using the strptime method, but the problem here is that I can
> only specify one format argument, which can be used to parse either a
> full date/time string or just a date string, but not both.
>
> While I could just try parsing with one format, then catch the
> ValueError in case it fails and try another format, it feels like there
> should be a more elegant way to do this.
>
> I do know about the dateutil package, but I'd prefer to stick to the
> stdlib for this.
>
> Any suggestions ?
>
> Wolfgang
>

If you're not sorted via stdlib how about http://crsmithdev.com/arrow/ ? 
  Haven't tried it myself as I've only just come across it.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: converting ISO8601 date and time string representations to datetime Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-11 23:54 +0100

csiph-web