Jump to content

help with 24 hour clock in script


Recommended Posts

Posted

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

Posted

a little explanation on it would be great smile.png

 

Pretty straight forward, you can can see the API :s

 

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

Posted (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 by Imateamcape
Posted

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

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...