473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

time.time()

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?

Jul 18 '05 #1
8 2931
On Sat, 24 Jan 2004 13:01:40 -0500, Bart Nessux <ba*********@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.
Jul 18 '05 #2
time.time() returns seconds since a particular time in the past ("the
Epoch"), not seconds since program start or anything like that.

import time
help(time.time)


Help on built-in function time:

time(...)
time() -> floating point number

Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
Jul 18 '05 #3
Terry Carroll wrote:
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.


I should have been more clear... here's the code:

x = time.time()
fp = os.popen("some_process", "r")
fp.read()
fp.close()
print (time.time()-x/60)/60

If fp runs for many hours (in my case it does), I want time.time() to
return the time it runs in seconds which I would then divide by 60 to
get the total amount of minutes which I would then divide by 60 to get
the total amount of hours that the process has ran... does that make
sense? I don't need to be super precise, just within 1 minute or so of
the actual amount of time that the process required to run.

Jul 18 '05 #4
> x = time.time()
fp = os.popen("some_process", "r")
fp.read()
fp.close()
print (time.time()-x/60)/60


Parenthesis are your friend:
print (time.time()-x)/3600

- Josiah
Jul 18 '05 #5
Bart Nessux wrote:
Terry Carroll wrote:
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.
I should have been more clear... here's the code:


That's not only clearer - that's different :-)
x = time.time()
fp = os.popen("some_process", "r")
fp.read()
fp.close()
print (time.time()-x/60)/60

If fp runs for many hours (in my case it does), I want time.time() to
return the time it runs in seconds which I would then divide by 60 to
get the total amount of minutes which I would then divide by 60 to get
the total amount of hours that the process has ran... does that make
sense? I don't need to be super precise, just within 1 minute or so of
the actual amount of time that the process required to run.

start = time()
start 1074980579.623781 sleep(7200)
duration = time() - start
print "duration in hours:", duration/60/60 duration in hours: 2.0 (time() - start) / 60 / 60 2.0

In the last expression, the parentheses are necessary, because - has lower
precedence than /, i. e. otherwise you would calculate time() -
(start/60/60). Note how I introduced an additional "duration" variable. If
a calculation does not yield the expected result, it is often helpful to
inspect some intermediate values.

Peter

PS: I cheated with my sleep() and time() functions:
def time(): .... global _time
.... try:
.... return _time
.... except NameError:
.... import time
.... _time = time.time()
.... return _time
.... def sleep(s):

.... global _time
.... try:
.... _time += s
.... except NameError:
.... import time
.... _time = time.time() + s

Jul 18 '05 #6
bart,

a-b/c evaluates as a-(b/c)

Jeff

Jul 18 '05 #7
Jeff Epler wrote:
bart,

a-b/c evaluates as a-(b/c)

Jeff


Ah, yes... silly me. That's the problem.

Jul 18 '05 #8
On Sat, 24 Jan 2004 16:25:01 -0500, Bart Nessux <ba*********@hotmail.com>
wrote:
Terry Carroll wrote:
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.


I should have been more clear... here's the code:

x = time.time()
fp = os.popen("some_process", "r")
fp.read()
fp.close()
print (time.time()-x/60)/60


Ah. You have a precedence problem.

Try:

print ((time.time()-x)/60)/60
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Stockwell | last post by:
I'm sure this has been asked before, but I wasn't able to find it. First off I know u can't change a tuple but if I wanted to increment a time tuple by one day what is the standard method to do...
6
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone...
3
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i...
6
by: Rebecca Smith | last post by:
Today’s question involves two time text boxes each set to a different time zone. Initially txtCurrentTime will be set to Pacific Time or system time. This will change with system time as we travel...
3
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to...
3
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And...
1
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time =...
2
by: Roseanne | last post by:
We are experiencing very slow response time in our web app. We run IIS 6 - windows 2003. I ran iisstate. Here's what I got. Any ideas?? Opened log file 'F:\iisstate\output\IISState-812.log'...
9
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.