We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › millis() rollover
Page Index Toggle Pages: 1
millis() rollover (Read 369 times)
millis() rollover
May 27th, 2009, 2:53pm
 
Does anyone know what millis() does if it exceeds the maximum value for an integer? I have a program which is to run indefinitely and I use millis() in a timer function. Will I have a problem after 24 or so days?
Re: millis() rollover
Reply #1 - May 27th, 2009, 3:15pm
 
An int's maximum value is 2147483647

2147483647 / 1000fps = 2147483.647
71582788.233 / 60 sec = 35791.3941
35791.3941 / 60 min = 596.523
596.523 / 24 hrs = 9.942

You have nine days before millis would theoretically stop working.

Or, if you set a counter to count on each frame, you could then approximate the current amount of milliseconds that have passed. At a framerate of 30, you would have 2 years.

Other than that you can use Java's Date object, and subtract the current milliseconds from the timestamp of the program's start. You would need to store this value as a long (int).
Page Index Toggle Pages: 1