문제

Preferably as a long.

All the example I can find are getting the date/time as a string and not any scalar value. :)

도움이 되었습니까?

해결책

If you really want the current time as a long, try System.currentTimeMillis(). Alternatively, you can use new Date().getTime().

However, using the current time as a random number generator seed is a very poor choice (at least, if you are using the random numbers for anything important, such as cryptography). You may wish to consider using a random source such as /dev/urandom (if available on your platform).

다른 팁

System.currentTimeMillis returns a long.

http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()

there is also System.nanoTime().

To generate a random number you can use this code:

var randomnumber=new Date().getUTCMilliseconds();
var rand = Math.floor((Math.random() * randomnumber) + 1); 
document.write(rand);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top