Results 1 to 8 of 8

Thread: System Time

  1. #1
    vasa is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Arrow System Time

    How to get System time that should run continuously until we stop..pls give a solution..

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    As you command: ;)

    Java 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.");
    (note: i just took a wild guess as to what you are actually asking)

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by mrmatt1111 View Post
    ....(note: i just took a wild guess as to what you are actually asking)
    Yep, as given the question, that's all anyone can do.

    To the original poster: Welcome to the forum. If you want more detailed or problem-specific help, you may wish to provide more detail about your problem. Best of luck, and again, welcome.

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  7. #7
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

Similar Threads

  1. setting system clocks time
    By pks in forum New To Java
    Replies: 4
    Last Post: 05-14-2009, 03:36 AM
  2. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 01:06 AM
  3. System time problem
    By dswastik in forum CLDC and MIDP
    Replies: 0
    Last Post: 04-08-2009, 01:36 PM
  4. set system time
    By @eddie.com in forum New To Java
    Replies: 3
    Last Post: 09-02-2008, 03:55 PM
  5. Urgent-Imp-Displaying message with respect to system time
    By garinapavan in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •