public static void main(String[] args) {
// 創建Canlendar對象
Calendar c =Calendar.getInstance();?
? ? ? ??
// 將Calendar對象轉換為Date對象
Date date =c.getTime();?
? ? ? ??
// 創建SimpleDateFormat對象,指定目標格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
? ? ? ??
// 將日期轉換為指定格式的字符串
String now = sdf.format(date);
System.out.println("當前時間:" + now);
}
}