Maverick Maverick - 7 months ago 52
Java Question

Java generate random int from timestamp

I am trying to generate a random int from timestamp, but below java code gives output in following format.

java.util.Date date= new java.util.Date();
System.out.println(new Timestamp(date.getTime()));

Output :

2010-03-08 14:59:30.252

Any java equivalent for python
print time.time()
which gives output like


To print the number of milliseconds from epoch to the Date object use System.out.println(Long.toString(new Date().getTime()));.

Otherwise if you just want the current count of milliseconds or nanoseconds since epoch, you have a couple options:

  • System.currentTimeMillis()
  • System.nanoTime()

both of which return a long.