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天后的日期

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章