-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

  • 1
    You can get its current value with `Syste.currentTimeMilis()`... – Usagi Miyamoto Aug 25 '17 at 09: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. – M. Prokhorov Aug 25 '17 at 09:30
  • maybe this can help. https://stackoverflow.com/a/7467299/6503002 – amicoderozer Aug 25 '17 at 09: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. – David Aug 25 '17 at 09:34
  • Yes Mr David that is what i need. Can you write an example? – Omar Al Iraqi Aug 25 '17 at 18:27

1 Answers1

-2
final long startTime= System.currentTimeMillis();
System.out.println("something");
final long stopTime= System.currentTimeMillis();
System.out.println("endfunction:"+ (stopTime - startTime));
simbabque
  • 53,749
  • 8
  • 73
  • 136