Date format and LocalDateTime

public static void main(String[] args) {
LocalDateTime local = LocalDateTime.now();
Date date = new Date();
//Date 类型的时间使用SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(date));
//LocalDateTime 类型的使用DateTimeFormatter
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(formatter.format(local));
}

Guess you like

Origin www.cnblogs.com/maohuidong/p/11815583.html