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

Debugging Java classes which are called from Windows batch files
Number to Words
IntelliJ Tomcat delayed war-deployment
Handling multiple events at the same time with JavaFx
Javafx pause between each timeline “cycle”
How to properly stop all the threads in Android?
Spring Data Rest + Spring Data Mongo - can't update numer of elements on list in object
Open an applet in Linux Terminal
Android Service to check whether the user screen on or off
Regex working online but not in program [duplicate]
incompatible generic return type
How to make logout without using sessionConcept in java
Spring security OAuth2 implementation
jpa criteria compare two strings in without considering spaces
Object creating
using web service in SQL Server 2012

Categories

HOME
image
minimum-spanning-tree
include
objectgears
networkx
esper
synchronization
adfs
cloudkit
offline
mapserver
postgres-xl
dynamics-crm-online
pc
connection-string
openedx
alpine
reverse-proxy
sox
accessor
cultureinfo
crystal-reports-2010
centos6.5
applozic
delicious-api
gsoap
socialengine
hybridauth
mozilla
geopositioning
wpf-controls
leading-zero
texmaker
unixodbc
qcombobox
xml-documentation
network-flow
react-scripts
fancybox-2
knockout-components
google-perftools
nbconvert
dynamics-sl
crosswalk-runtime
mediaelement
spring-android
nxt
sts-springsourcetoolsuite
database-optimization
intrusion-detection
qgraphicsview
captivenetwork
wapiti
icu4j
computer-algebra-systems
riak-cs
census
formatjs
ng-animate
id3v2
java-metro-framework
websocket4net
castle
wp-query
app42
jsctypes
runtime.exec
odata4j
sharp-repository
ember-app-kit
selected
venn-diagram
pysimplesoap
chrono
dotnethighcharts
custom-backend
qt-jambi
oncheckedchanged
cxxtest
infrastructure
sproutcore-2
firefox-5
text-coloring
project-hosting

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