import java.text.SimpleDateFormat;
import java.util.Calendar;
方法一:
SimpleDateFormat sdf =
new
SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"
);
String ly_time = sdf.format(
new
java.util.Date());
System.
out
.println(
"现在时间是:"
+ly_time);
结果:现在时间是:2013-04-21 16:50:43
方法二:
String ly_time =
new
SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"
).format(Calendar.getInstance().getTime());
System.
out
.println(
"现在时间是:"
+ly_time);
结果:现在时间是:2008-04-21 16:50:43