// 参考: https://www.cnblogs.com/blog5277/p/6407463.html
public class DateTest {
// 支持时分秒
private static String LocalDateTimeTest(){
LocalDateTime date = LocalDateTime.now();
String res = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
return res;
}
// 不支持时分秒
private static String LocalDateTest(){
LocalDate date = LocalDate.now();
String res = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
return res;
}
// 时间戳
private static long getTimestamp(){
return Timestamp.valueOf(LocalDateTimeTest()).getTime();
}
public static void main (String[] args) {
System.out.println(LocalDateTimeTest());
System.out.println(LocalDateTest());
System.out.println(getTimestamp(LocalDateTest()));
}
}