请在控制台以“xxxx年xx月xx日 xx时xx分xx秒”的格式打印当前系统时间。 要求: 1:使用Date+SimpleDateFormat完成一遍, 2:再使用LocalDateTime+DateTimeFormatter完成一遍;
public class Test1 { public static void main(String[] args) throws ParseException { // 使用Date+SimpleDateFormat Date date = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); String formattedDate = simpleDateFormat.format(date); System.out.println(formattedDate); // 使用LocalDateTime+DateTimeFormatter LocalDateTime currentDateTime = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"); String formattedDateTime = currentDateTime.format(formatter); System.out.println(formattedDateTime); } }