Lewis Posted December 18, 2016 Share Posted December 18, 2016 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 Quote Link to comment Share on other sites More sharing options...
House Posted December 18, 2016 Share Posted December 18, 2016 https://docs.oracle.com/javase/8/docs/api/java/util/Date.html Quote Link to comment Share on other sites More sharing options...
Lewis Posted December 18, 2016 Author Share Posted December 18, 2016 https://docs.oracle.com/javase/8/docs/api/java/util/Date.html a little explanation on it would be great Quote Link to comment Share on other sites More sharing options...
House Posted December 18, 2016 Share Posted December 18, 2016 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 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 18, 2016 Share Posted December 18, 2016 (edited) 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, 2016 by Imateamcape Quote Link to comment Share on other sites More sharing options...
House Posted December 18, 2016 Share Posted December 18, 2016 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. Quote Link to comment Share on other sites More sharing options...