-4

How I can use the CPU time as variable in java where I need to define a variable with dynamic value increase with time pass example

int cpuTime; first: cpuTime = 0 because but after 20 second cpuTime = 20 and after 60 second cpuTime= 60 and so on? where, i need to check some condition with time pass. example if cpuTime > p-10 do {}

Best regards

5
  • 1
    You can get its current value with Syste.currentTimeMilis()... Commented Aug 25, 2017 at 9:29
  • 1
    @UsagiMiyamoto, millis is not a CPU time though - it's wall time, what internal system clock produces. Although looking at the question, OP might've been asking about millis and not CPU time all along. Commented Aug 25, 2017 at 9:30
  • maybe this can help. stackoverflow.com/a/7467299/6503002 Commented Aug 25, 2017 at 9:31
  • 2
    If you're looking for an ever-increasing count of seconds, are you instead looking for epoch time? You could start it at 0 by simply recording the initial value and subtracting it from further values. Commented Aug 25, 2017 at 9:34
  • Yes Mr David that is what i need. Can you write an example? Commented Aug 25, 2017 at 18:27

1 Answer 1

-2
final long startTime= System.currentTimeMillis();
System.out.println("something");
final long stopTime= System.currentTimeMillis();
System.out.println("endfunction:"+ (stopTime - startTime));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.