December 18, 20169 yr Im having a bit of trouble adding: if current system time is equal to 8am/1pm/12am + random value between 0 seconds and 1 hour (i can generate a random amount of time between 0 seconds and 1 hour already. just need help getting: if current system time == Xam/pm) been looking into: http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html but i cant seem to get it working i also looked into just using: if System.currentTimeMillis() == RANDOMMILLIS { } but its too confusing figuring out any help is much appreciated
December 18, 20169 yr Author https://docs.oracle.com/javase/8/docs/api/java/util/Date.html a little explanation on it would be great
December 18, 20169 yr a little explanation on it would be great Pretty straight forward, you can can see the API It helps you track time and you can translate a Date to a long and vice versa You can compare the current Date with the future Date you set using your random interval by using Date#after() or Date#before
December 18, 20169 yr honestly, doesnt seem to be a good idea to do it that way. think it might be better to go something like this: private long lastUpdate = System.currentTimeMillis(); . . . if(System.currentTimeMillis() - lastUpdate <= MethodProvider.random(2000, 3000)) { //some random time period (this would complete the action every 2-3 seconds) completeAnAction(); lastUpdate = System.currentTimeMillis(); } it looked like this was what you were trying to get at, at least Edited December 18, 20169 yr by Imateamcape
December 18, 20169 yr honestly, doesnt seem to be a good idea to do it that way. think it might be better to go something like this: private long lastUpdate = System.currentTimeMillis(); . . . if(System.currentTimeMillis() - lastUpdate <= MethodProvider.random(2000, 3000)) { //some random time period (this would complete the action every 2-3 seconds) completeAnAction(); lastUpdate = System.currentTimeMillis(); } it looked like this was what you were trying to get at, at least This^ Use the Date class and the method above rather than a Timer.
Create an account or sign in to comment