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 7092975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:22:53+00:00 2026-05-28T08:22:53+00:00

I got an interesting time-travel problem today, using the following code: for (int i

  • 0

I got an interesting “time-travel” problem today, using the following code:

for (int i = 0; i < 1; i++){
    long start = System.currentTimeMillis();
    // Some code here
    System.out.print(i + "\t" + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    // Some code here
    System.out.println("\t" + (System.currentTimeMillis() - start));
}

And I got the result

0   15  -606

And it seems that it is not repeatable. Anyone has any clues on what happened inside during the running time? Just curious…

New edit: I used a small test to confirmed the answers below. I run the program and change the system time during the run, and finally repeat the “time-travel”:

0   -3563323    163

Case closed. Thanks guys!

More words: both currentTimeMillis() and nanoTime() are system-timer based, so they will be not monotonic if the system timer is updated (turned back, specifically). It is better to use some internet-based timer for such cases.

  • 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-28T08:22:54+00:00Added an answer on May 28, 2026 at 8:22 am

    System.currentTimeMillis() depends on the system time. So it could be modified by third party systems.

    For measuring time is System.nanoTime() the better option.

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

Sidebar

Related Questions

I ran into an interesting problem at work today. I got a request to
I've got an interesting box-model problem here. I have a header full of links,
(I asked this question in another way , and got some interesting responses but
Today I got my book Head First Design Patterns in the mail. Pretty interesting
I've got an interesting problem that's cropped up in a sort of pass based
I've got a real little interesting (at least to me) problem to solve (and,
I'm having an interesting but difficult problem with my JavaScript code. Basically, I'm trying
I've got some RDL using it in a (windows forms) .net 2.0 app. When
I got an interesting bug report today. I have a DispatcherTimer whose Tick calls
Here's an interesting problem: I'm using ReadProcessMemory (from within C#) to write a simple

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.