Java 中LocalDate 的使用

 LocalDate 的使用:

        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("localDate="+localDate);         //localDate=2019-09-16
        System.out.println("localTime="+localTime);         //localTime=10:11:01.625851400
        System.out.println("localDateTime="+localDateTime); //localDateTime=2019-09-16T10:11:01.625851400
        System.out.println("localDate="+localDate.getDayOfWeek().getValue());         //获取星期几
        System.out.println("localDate="+localDate.get(ChronoField.ALIGNED_WEEK_OF_MONTH));         //获取当前月的第几周
        System.out.println(localDate.getDayOfYear());            //获取本年中截止到今天已经过去的天数

        System.out.println(localDate.with(TemporalAdjusters.firstDayOfMonth()));  //得到所在月的第一天
        System.out.println(localDate.withDayOfMonth(2));  //得到所在月的第二天
        System.out.println(localDate.with(TemporalAdjusters.lastDayOfMonth()));  //得到所在月的最后一天
        System.out.println(localDate.plusDays(20));  //得到20天后的日期

 

你可能感兴趣的:(Java,开发)