java
How do I make a variable equal the system time and now keep changing to the system time
Hi how do I make int x = (Sys.getTime() * 1000) / Sys.getTimerResolution(); equal the system time without x constantly changing to the system time after that. For example if I write a piece of code that waits for 100 milliseconds to do something (x + 100), x will always be 100 above the system time. Thanks for any help.
When you assign a value to a variable, that value doesn't change unless you assign a new value to the variable. Therefore, if you assign a value to x once, it won't change. The value of x will reflect the system time at the time the assignment was made. It won't automatically update as time passes.
You can schedule a Timer to keep the variable containing the desired value. However, on this particular case, the best solution is using a function that returns that value, instead of a variable.
you can use a thread to keep the current time variable updated.
Well simply: Use the new Date() to get the system time. Get it in milliseconds. And then add to it your time in milliseconds. And finally make a new Date(long date) with your new time. long x=new Date().getTime()+10000; Date dt=new Date(x); System.out.println(dt); And to update your variable, you can use a Thread: Thread myThread = new Thread() { public void run() { long x=new Date().getTime()+10000; Date dt=new Date(x); System.out.println(dt); } };
Related Links
nextLine().charAt(0) inside a switch statement
Scrabble code in java
Spring - pass parameters through link
Fast way to get a coordinate(x,y) from an ArrayList?
Iterator - Struts2 and Apache Tomcat 8
How to parse time in correct timezone java?
Parse a date from json
JAVA toLowerCase() is getting symbols
how to crop the detected face image in opencv java
play framework : Pass date to view
What is the use of JasperListener and other listeners in Tomcat
How do I execute a program which contains two classes independently in eclipse?
The annotation “#Added” is disallowed for this location, when using custom annotation with events in CDI
CORB Job : Handle ServerConnectionException: Connection reset by peer
How to chain multiple RxJava's groupBy() methods such as groupBy().groupBy()
Storm bolt instances communication