how to convert current date into string in java?
This will show the date and time, not just the current date.
Adamski
2010-05-31 10:24:28
Well sorry for overachieving.
jasonmp85
2010-05-31 10:25:03
+3
A:
Use a DateFormat
implementation; e.g. SimpleDateFormat
.
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
System.err.println(df.format(new Date()));
Adamski
2010-05-31 10:22:42
+5
A:
// GET DATE & TIME IN ANY FORMAT
import java.util.Calendar;
import java.text.SimpleDateFormat;
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
public static String now() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
}
Taken from here
Itay
2010-05-31 10:23:12