How to get current timestamp in string format in Java? "yyyy.MM.dd.HH.mm.ss"

user3388884 picture user3388884 · Apr 14, 2014 · Viewed 551.3k times · Source

How to get timestamp in string format in Java? "yyyy.MM.dd.HH.mm.ss"

String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Timestamp());

This is what I have, but Timestamp() requires an parameters...

Answer

Jigar Joshi picture Jigar Joshi · Apr 14, 2014

Replace

new Timestamp();

with

new java.util.Date()

because there is no default constructor for Timestamp, or you can do it with the method:

new Timestamp(System.currentTimeMillis());