Problem converting System.currentTimeMillis() to current time and int
in
Programming Questions
•
11 months ago
I have an analog clock applet that runs at 15 frames per second and uses the value 'framecount' to set the angles of the arms.
I get framecount using
framecount = int(System.currentTimeMillis() - 1353555000000L)*(.015);
And the minute arm is drawn using
pushMatrix();
translate(width/2, height/2);
rotate(framecount*TWO_PI/(60*900));
stroke(50, 15);
strokeWeight(2);
line(0, 0, 0, -iR/2);
ellipse(0, -iR/2, 15, 15);
strokeWeight(1);
popMatrix();
the important line being
roate(framecount*TWO_PI/(60*900));
where the angle is set to the frame times 1 full rotation divided by 60 times the number of frames in 1 minute, so that 1 full rotation is made each hour.
The clock does not show the correct minute time. The -1353555000000L just takes off enough digits from the system time to make it an int. Subtracting (42L*365L*24L*60L*60L*1000L) [to get time since Jan 1st 2012] does not make it small enough for int or float values.
1