/**
* java编程题:将某个时间以固定格式转化成字符串
*/
public class Test {
public static void main(String[] args) {
Date now = new Date(); //当前时间
System.out.println(formatDateToString(now)); //打印结果
}
private static String formatDateToString(Date date){
//定义字符串格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sdf.format(date); // 格式化日期,并得到字符串
return dateStr; // 返回结果
}
}