Time Handling 5 in java8 - Date Tools

Next, take a look at the operation of the tool class:

        LocalDate today = LocalDate.now();
        System.out.println(today.getYear()+"Is the year a leap year?"+today.isLeapYear());
        System.out.println(today.isBefore(LocalDate.of(2015,1,1)));
        System.out.println(today.atTime(LocalTime.now()));

        System.out.println("10天后 "+today.plusDays(10));
        System.out.println("3周后 "+today.plusWeeks(3));
        System.out.println("20 months later"+today.plusMonths(20));

        System.out.println("10天前 "+today.minusDays(10));
        System.out.println("3周前 "+today.minusWeeks(3));
        System.out.println("20月前 "+today.minusMonths(20));

        System.out.println("月初是"+today.with(TemporalAdjusters.firstDayOfMonth()));
        LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear());
        System.out.println("The end of the year is"+lastDayOfYear);

        Period period = today.until(lastDayOfYear);
        System.out.println("The end of the year is "+period);
        System.out.println("Months left"+period.getMonths());

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326258862&siteId=291194637