How to get System time that should run continuously until we stop..pls give a solution..
Printable View
How to get System time that should run continuously until we stop..pls give a solution..
As you command: ;)
(note: i just took a wild guess as to what you are actually asking)Code:long startTime = System.currentTimeMillis();
int count = 0;
for(int j = 0; j < Integer.MAX_VALUE; j++)
count++; //spin our wheels
long endTime = System.currentTimeMillis();
System.out.println("It took " + (endTime-startTime) + "ms to complete.");
As I found out after a long and embarrassing journey, System.currentTimeMillis() may only update every 10-15 millis. That's fine if your dealing with 1/2 a second or longer, but it does add a small uncertainty for smaller periods.
I agreed with you Steve.
For Java doc...
Quote:
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
I'm not sure the exact requirements here, but in designs I always try to work with avoiding the date time. It's always mess, we cannot deal with the exact time(even in milliseconds), and the best way is to deal with time stamp, or time interval. Actually that's what most of the industrial applications do. Calender make sense in Date/Time a lot.
BTW, don't use System.nanoTime() if you need actual time. The "nanos" are accurate in the sense that a billion nanos are not exactly one second. They are only useful for relative comparisons.
Yes, as I said earlier the most suitable way is avoid the deal with exact time as much as possible. Deal with the time interval make sense in all the way.