user3703289
user3703289

Reputation: 346

Convert timestamp to string

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?

Upvotes: 20

Views: 131600

Answers (2)

amit bhardwaj
amit bhardwaj

Reputation: 883

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

Upvotes: 29

S. Tersteeg
S. Tersteeg

Reputation: 141

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

Upvotes: 0

Related Questions