private static int MsFromTime(double t) { double result; result = t % msPerSecond; if (result < 0) { result += msPerSecond; } return (int)result; }