package com.hr.util.test.date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateTimeFormatterTest {
public static void main(String[] args) {
//将字符串转换为Date类型
String dateStr = "2020-08-18";
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate parse = LocalDate.parse(dateStr, timeFormatter);
System.out.println(parse);
//Date转换为字符串
LocalDateTime date = LocalDateTime.now();
System.out.println(date);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss a");
String format = date.format(formatter);
System.out.println(format);
}
}