Friday, April 19, 2013

Easiest Way to print Timestamp in Java

Rather than using Calendar.getTime() we can use java.sql.Timestamp class to get the time stamp which gives date and time till millisecond precision.

System.out.println(new Timestamp(System.currentTimeMillis()));


Above will give you current timestamp in this format: 2010-07-27 16:37:45.39