Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6740691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:38:09+00:00 2026-05-26T11:38:09+00:00

I just found System.currentTimeMillis is not accurate on windows XP, now I tried System.nanoTime()

  • 0

I just found System.currentTimeMillis is not accurate on windows XP, now I tried System.nanoTime() with the same code.

Since 1ms = 1,000,000ns, so I think the result should be 15,000,000ns, but it’s not.

See the sample code:

public class NanoTime {
    public static void main(String[] args) {
        long start = 0;
        long end = 0;
        while (true) {
            if (start == 0) {
                start = System.nanoTime();
            } else {
                long current = System.nanoTime();
                if (current != start) {
                    end = current;
                    break;
                }
            }
        }
        System.out.println("The time interval of your OS: " + (end - start) + "ns");
    }
}

The result is:

The time interval of your OS: 655ns

Seems it’s much better than System.currentTimeMillis(). But why? Can we believe this result?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:38:10+00:00Added an answer on May 26, 2026 at 11:38 am

    If your Windows XP has SP3 then you can believe that result… on Windows the JVM implements nanoTime() internally using QueryPerformanceCounter/QueryPerformanceFrequency API which is basically located in HAL (Hardware abstraction layer) and uses some CPU-internal interval instructions which are rather accurate… it is only good for interval measurements NOT for time handling…

    For a more elaborate description see http://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks and http://juliusdavies.ca/posix_clocks/clock_realtime_linux_faq.html

    EDIT – as per comment:

    The above mentioned function are used by the JVM itself internally when nanoTime is called which has absolutely NOTHING to do with JNI – they are not exposed to Java code!

    EDIT 2 – as per comments:

    nanoTime() is the right tool to measure elapsed time accurately while currentTimeMillis is the right tool to handle absolute time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just found out that the video output of the iPad is not a system
I just found in some code that it uses System.Data.SqlTypes.SqlString ? I haven't seen
i was just checking the behaviour of fork system call and i found it
So I just found this code example online a while ago and I'm going
I just found Data::Section and I got interested in it. Unfortunately, I simply cannot
I just found out how to loop an array based on another array, but
I just found out this weird behavior, is this a bug or what am
I just found out that every time onclick event for my <button> placed inside
I just found out about ie7-js ; IE7 is a JavaScript library to make
I just found out about superfish and currently using it on an asp.net. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.