20

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?

Aruna
  • 11,959
  • 3
  • 28
  • 42
user3703289
  • 347
  • 1
  • 3
  • 9
  • possible duplicate of [How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?](http://stackoverflow.com/questions/1459656/how-to-get-the-current-time-in-yyyy-mm-dd-hhmisec-millisecond-format-in-java) – Basil Bourque Oct 14 '14 at 15:59

2 Answers2

29

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

amit bhardwaj
  • 883
  • 2
  • 8
  • 18
0

new Date().toString();

http://www.mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/

Dateformatter can make it to any string you want

S. Tersteeg
  • 141
  • 4