java.time.LocalDate格式化 及 LocalDate转Date
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())); } }
当看到一些不好的代码时,会发现我还算优秀;当看到优秀的代码时,也才意识到持续学习的重要!--buguge
本文来自博客园,转载请注明原文链接:https://www.cnblogs.com/buguge/p/16472073.html