Convert timestamp to string

user3703289 picture user3703289 · Oct 14, 2014 · Viewed 102.2k times · Source

In java I need to display 'time of the program start'

It must be in String.

How do I get the current time, and then convert it to a String?

Answer

amit bhardwaj picture amit bhardwaj · Oct 14, 2014

try this

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String string  = dateFormat.format(new Date());
System.out.println(string);

you can create any format see this