Quite some time ago, Jorge produced a class that might make a useful starting point for you.
https://groups.google.com/d/msg/androidscript/aVYj-LS9O4g/keLpDaD1t5cJ
The Math and Date functions are not specific to DroidScript, you can find them in the docs by looking in the JavaScript reference.
The following links are to the online version of that reference.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime
With regard to your number2 variable problem, if you declare a variable outside any function, it will be global and should be available from anywhere in the app.
If you declare it inside a function (including the OnStart function) it will be local, so you can only access it inside that function.
For more detail see http://www.w3schools.com/js/js_scope.asp