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


Groups > comp.lang.python > #39665

time as float since Jan 1, 0001?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!roy
From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject time as float since Jan 1, 0001?
Date Sat, 23 Feb 2013 08:29:01 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Lines 19
Message-ID <roy-41E67E.08290123022013@news.panix.com> (permalink)
NNTP-Posting-Host localhost
X-Trace reader1.panix.com 1361626142 13827 127.0.0.1 (23 Feb 2013 13:29:02 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Sat, 23 Feb 2013 13:29:02 +0000 (UTC)
User-Agent MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
Xref csiph.com comp.lang.python:39665

Show key headers only | View raw


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?

Back to comp.lang.python | Previous | NextNext 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