Go Down

Topic: Reset millis (Read 6342 times) previous topic - next topic


I have never used or even seen the modulo (%) used anywhere before, but it's an ingenious way of achieving this result, and one which I would have never considered.
Assuming that the counter is started at midnight, (to gather a full day's data), what would happen if after 49 days and millis overflows and returns back to zero, say at midday when myMilliseconds = 43200000 ?
Will myMilliseconds continue on to  43200001, 2, 3 ect.
Or, will it return back to zero (and start the 24 hour counter from midday instead of midnight, throwing the 24hr period out of sync).

Because 4294967296 % 86400000 = 61367296 (4294967296 is the equivalent of the rollover 0)), then the next day at midnight you're not be at zero, but 61,367,296. You'd have to take that into account from now on, perhaps by subtracting this value before taking the modulo. However, unless you really plan to run something for 50 days, this likely won't be an issue.

Go Up