Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed2.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'conversions': 0.07; 'suppose': 0.07; 'lawrence': 0.09; 'matplotlib': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "wouldn't": 0.11; 'represents': 0.15; 'cleaner': 0.16; 'iirc': 0.16; 'integer.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'ugly.': 0.16; 'wrote:': 0.17; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; "i'm": 0.29; 'from:addr:yahoo.co.uk': 0.32; 'could': 0.32; 'turns': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'skip:d 20': 0.34; 'wrong': 0.34; 'subject:?': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'too': 0.36; 'subject:: ': 0.38; 'mark': 0.38; 'supports': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'days': 0.60; 'you.': 0.61; 'subject:, ': 0.61; 'smith': 0.71; 'conversion?': 0.84; 'url:api': 0.84; 'do:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: time as float since Jan 1, 0001? Date: Sat, 23 Feb 2013 13:41:24 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-18-29-221.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 In-Reply-To: X-Antivirus: avast! (VPS 130223-0, 23/02/2013), Outbound message X-Antivirus-Status: Clean 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361626870 news.xs4all.nl 6972 [2001:888:2000:d::a6]:39782 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39667 On 23/02/2013 13:29, Roy Smith wrote: > I'm working with matplotlib.plot_date(), which represents time as > "floats starting at January 1st, year 0001". Is there any > straight-forward way to get that out of a datetime? > > datetime.toordinal() gives me the number of days since that epoch, but > as an integer. I figured it wouldn't be too hard to just do: > > t.toordinal() + t.time().total_seconds() > > except it turns out that only timedelta supports total_seconds(); time > doesn't! > > I suppose I could do: > > t.toordinal() + t.hour / 24.0 \ > + t.minute / 1440.0 \ > + t.second / 86400.0 > > but that's really ugly. Is there no cleaner way to do this conversion? > IIRC you needn't bother, matplotlib will do all the conversions for you. In the highly likely case that I'm wrong this should help http://matplotlib.org/api/dates_api.html#module-matplotlib.dates -- Cheers. Mark Lawrence