Maverick Maverick - 1 year ago 168
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download