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


Groups > comp.lang.python > #39667

Re: time as float since Jan 1, 0001?

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 <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.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 <breamoreboy@yahoo.co.uk>
Subject Re: time as float since Jan 1, 0001?
Date Sat, 23 Feb 2013 13:41:24 +0000
References <roy-41E67E.08290123022013@news.panix.com>
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 <roy-41E67E.08290123022013@news.panix.com>
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2342.1361626870.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

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


Thread

time as float since Jan 1, 0001? Roy Smith <roy@panix.com> - 2013-02-23 08:29 -0500
  Re: time as float since Jan 1, 0001? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-23 13:41 +0000
    Re: time as float since Jan 1, 0001? Roy Smith <roy@panix.com> - 2013-02-23 08:49 -0500
      Re: time as float since Jan 1, 0001? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-23 14:08 -0500
  Re: time as float since Jan 1, 0001? Chris Angelico <rosuav@gmail.com> - 2013-02-24 00:45 +1100

csiph-web