-1

My aim is to speed up or slow down time.

Note: All units of time in double quotes ("some time") are NOT real units of time. They are notional units of time.

I want to make a clock which is runs exactly like a regular clock, except that 250 milliseconds = 1 "second", 60 "seconds" or rather 250 * 60 milliseconds = 1 "minute" etc. I also want to be able to change this clock to use any another value of milliseconds as 1 second eg 1000 (normal,real world time) , 6000 ms (ie 6 sec = 1 "sec") etc.

Is there any reliable API or code to do this ? If not, then how do I do it ?

I saw a question on SO, but did not get any code, API or suggestions on how to implement such a clock or what could be the potential problems in such a clock - Java - Creating an Internal Clock

That post talks about callback, but I don't know if its the best and problem free way to make my clock.

Community
  • 1
  • 1
Time
  • 1,551
  • 2
  • 13
  • 14
  • 1
    This question does not seem to be bad. I am confident that most people would find it worth looking at, if not very interesting or a good question. Why the -1 ? – Time Mar 31 '13 at 10:43

2 Answers2

1

Obviously create a class MyClock.java. On instantiation save the current System Time. Implement a method long getTime() that takes the diference from now and the saved time on instatiation. Then apply delatation on the given miliiseconds (multiply by 4) ... rest is yours.

PeterMmm
  • 24,152
  • 13
  • 73
  • 111
1

One way would be to just base your time off of the system clock, for example:

class CustomClock()
{
    private final long offset;

    public CustomClock(){
        offset = System.currentTimeMillis();
    }

    public long getSeconds()
    {
        return ((System.currentTimeMillis() - offset) / 250);
    }

    /* ... */
}

Then your code would look like

CustomClock clock = new CustomClock();
clock.getSeconds();    // Returns the number of "seconds" since you created 
                       //  the CustomClock object.
jedwards
  • 29,432
  • 3
  • 65
  • 92