time.time()

Terry Carroll carroll at tjc.com
Sat Jan 24 13:55:54 EST 2004


On Sat, 24 Jan 2004 13:01:40 -0500, Bart Nessux <bart_nessux at hotmail.com>
wrote:

>am I doing this wrong:
>
>print (time.time() / 60) / 60	#time.time has been running for many hours
>
>if time.time() was (21600/60) then that would equal 360/60 which would 
>be 6, but I'm not getting 6 so I'm not doing the division right, any tips?

time.time() returns the number of seconds since the epoch.  The epoch is
generally Jan 1, 1970; you can check by trying time.gmtime(0).

You're expecting time.time() to be 21600/60, or, in other words, for
time() to be 1548; but 1548 seconds is only about 25 minutes.  It's been a
little more than 34 years since Jan 1, 1970, so the number you should
expect from time.time() should be in the neighborhood of 34 years * 365.25
days/year * 24 hours/day * 60 min/hour * 60 sec/min = 1072958400.

Trying time.time() directly confirms this:

>>> time.time()
1074969863.888

Yeah, it's not on the nose, but close enough for a sanity check.  By the
way, this is usually a good thing to try when you're lost at sea like this
-- go back to the original input data, in this case, time.time() output,
and see if it's giving you what you expect.

It sounds like you're thinking time.time() does something else, which
you're trying to do.  What is that?  There might be another function for
you.



More information about the Python-list mailing list