Results 1 to 8 of 8
Thread: System Time
- 08-20-2009, 09:24 PM #1Member
- Join Date
- Aug 2009
- Rep Power
- 08-20-2009, 09:57 PM #2
As you command: ;)
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.");
- 08-21-2009, 05:25 AM #4
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.
- 08-21-2009, 05:41 AM #5
I agreed with you Steve.
For Java doc...
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.
- 08-21-2009, 05:47 AM #6
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.
- 08-21-2009, 07:23 AM #7
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.
- 08-22-2009, 03:36 PM #8
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.
- By pks in forum New To JavaReplies: 4Last Post: 05-14-2009, 04:36 AM
- By verbazon in forum New To JavaReplies: 1Last Post: 04-13-2009, 02:06 AM
- By dswastik in forum CLDC and MIDPReplies: 0Last Post: 04-08-2009, 02:36 PM
- By @eddie.com in forum New To JavaReplies: 3Last Post: 09-02-2008, 04:55 PM
- By garinapavan in forum New To JavaReplies: 1Last Post: 08-03-2007, 03:17 PM