undefined
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class TestMain {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();//.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
// 格式化LocalDate或LocalTime
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
System.out.println(localDate.format(formatter));
// LocalDate转Date
System.out.println(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
LocalDateTime localTime = LocalDateTime.now();
// LocalDateTime转Date
System.out.println(Date.from(localTime.atZone(ZoneId.systemDefault()).toInstant()));
}
}
Original: https://www.cnblogs.com/buguge/p/16472073.html
Author: buguge
Title: java.time.LocalDate格式化 及 LocalDate转Date
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/615833/
转载文章受原作者版权保护。转载请注明原作者出处!