Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51919
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: outputting time in microseconds or milliseconds |
| Date | 2013-08-04 13:38 +0000 |
| References | <b5df0633-c6fe-4489-adda-5b9f270a904d@googlegroups.com> <07f6b1c7-069d-458b-a9fe-ff30c09f2f2d@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.179.1375623543.1251.python-list@python.org> (permalink) |
matt.doolittle33@gmail.com wrote:
> ok so now i import the module like this:
>
> from time import strftime, time
>
> i made the write statement like this:
>
> self.logfile.write('%s\t'%(str(strftime("%Y-%m-%d", ))))
> self.logfile.write('%s\t'%(str(strftime("%H:%M:%S", ))))
> self.logfile.write('%s\t'%(str(time())))
>
> (oh and btw,i know the code is hacker ugly).
> and the output is this:
>
> 2013-08-03 23:59:34 1375588774.89
> 2013-08-03 23:59:35 1375588775.06
> 2013-08-03 23:59:35 1375588775.25
> 2013-08-03 23:59:35 1375588775.43
> 2013-08-03 23:59:35 1375588775.80
> 2013-08-03 23:59:35 1375588775.99
> 2013-08-03 23:59:35 1375588775.99
> 2013-08-03 23:59:35 1375588775.99
> 2013-08-03 23:59:35 1375588776.00
> 2013-08-03 23:59:36 1375588776.15
> 2013-08-03 23:59:36 1375588776.15
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.16
> 2013-08-03 23:59:36 1375588776.34
> 2013-08-03 23:59:36 1375588776.35
> 2013-08-03 23:59:36 1375588776.35
> 2013-08-03 23:59:36 1375588776.35
>
> the first two columns are for eyes so if they are a microsecond apart it doesn't matter.
But if the time is close enough to midnight, they'll be a *day* apart,
as I (and others) said before. It's also hard to imagine why you
resist the good advice you've been getting about formatting. You can
do both the date and time with one call to strftime().
> the numbers in the third column are for calculating duration which is
> where i need the precision.
>
> Why is it only giving me the centisecond precision? the docs say i should get microsecond precision with the code i put together.
>
Have you done any experimenting to decide which logic was losing those
extra digits? Sit in the debugger, and do a t = time.time()
Then investigate what t looks like,
by repr(t), str(t), and "something" %t
(for various values of "something")
....
from time import time, localtime, strftime
now = time() #make a single call to get the time in seconds (float)
localnow = localtime(now)
out12 = strftime("%Y-%m-%d\t%H:%M:%S\t", localnow)
out3 = "%.6f" % now
self.logfile.write(out12 + out3)
You still have the problem that out12 is in the local time zone, while
out3 is in DCT. But as you say, these are for different audiences, and
presumably you won't really be putting them in the same file.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
outputting time in microseconds or milliseconds matt.doolittle33@gmail.com - 2013-08-02 03:54 -0700
Re: outputting time in microseconds or milliseconds Dave Angel <davea@davea.name> - 2013-08-02 12:08 +0000
Re: outputting time in microseconds or milliseconds Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-08-02 13:59 +0200
Re: outputting time in microseconds or milliseconds matt.doolittle33@gmail.com - 2013-08-02 06:17 -0700
Re: outputting time in microseconds or milliseconds Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-08-05 08:15 +0200
Re: outputting time in microseconds or milliseconds Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-02 12:35 +0000
Re: outputting time in microseconds or milliseconds matt.doolittle33@gmail.com - 2013-08-02 08:09 -0700
Re: outputting time in microseconds or milliseconds Skip Montanaro <skip@pobox.com> - 2013-08-02 07:37 -0500
Re: outputting time in microseconds or milliseconds matt.doolittle33@gmail.com - 2013-08-02 07:18 -0700
Re: outputting time in microseconds or milliseconds Skip Montanaro <skip@pobox.com> - 2013-08-02 10:15 -0500
Re: outputting time in microseconds or milliseconds Chris Angelico <rosuav@gmail.com> - 2013-08-02 13:50 +0100
Re: outputting time in microseconds or milliseconds matt.doolittle33@gmail.com - 2013-08-04 04:30 -0700
Re: outputting time in microseconds or milliseconds Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-08-04 13:57 +0200
Re: outputting time in microseconds or milliseconds Dave Angel <davea@davea.name> - 2013-08-04 13:38 +0000
Re: outputting time in microseconds or milliseconds Roy Smith <roy@panix.com> - 2013-08-04 10:33 -0400
Re: outputting time in microseconds or milliseconds matt.doolittle33@gmail.com - 2013-08-07 19:51 -0700
Re: outputting time in microseconds or milliseconds Skip Montanaro <skip@pobox.com> - 2013-08-08 07:03 -0500
Re: outputting time in microseconds or milliseconds Roy Smith <roy@panix.com> - 2013-08-08 09:30 -0400
csiph-web