Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 689
user3703289 Avatar asked Oct 14 '14 12:10

user3703289


People also ask

How do you convert timestamps to hours?

To convert time to a number of hours, multiply the time by 24, which is the number of hours in a day. To convert time to minutes, multiply the time by 1440, which is the number of minutes in a day (24*60). To convert time to seconds, multiply the time time by 86400, which is the number of seconds in a day (24*60*60 ).


1 Answers

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

like image 184
amit bhardwaj Avatar answered Oct 10 '22 05:10

amit bhardwaj