Jump to content

help with 24 hour clock in script


Lewis

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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