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

Categories

HOME
wso2-am
jdo
atom-editor
ngrx
kde
iot
amazon-ecs
retrofit
fingerprint
flyway4
upload
autotools
contact
adfs
slurm
google-translate
adobe-analytics
export-to-csv
correlation
google-cloud-spanner
remote-access
zebra-printers
try-catch
windows-7-x64
undefined
oracle-coherence
sms-gateway
visual-composer
emulator
amazonsellercentral
scriptcs
sox
dcevm
jndi
entitlements
fifo
assistant
google-cloud-nl
fabric8
temporary-files
arena-simulation
qcombobox
angular-resource
google-datalayer
logparser
dotnetzip
csound
diagnostics
nodebb
capacity
pdfclown
or-tools
angular-strap
ableton-live
dstu2-fhir
mathematica-frontend
multiple-regression
simplewebrtc
hover-over
sdf
pyke
python-3.2
emailrelay
ami
iiviewdeckcontroller
sonarqube5.1.2
inmobi
website-monitoring
tt-news
mdt
contenttype
wp-query
xceed-datagrid
braille
aqtime
dotnetnuke-5
http-unit
anonymous-methods
unc
chuck
broken-links
enter
gwt-ext
appendto
floating
virtual-functions
xetex
data-acquisition
ntvdm.exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App