首页javadateJava Data Type - 如何使用时间调整器来调整日期

Java Data Type - 如何使用时间调整器来调整日期

我们想知道如何使用时间调整器来调整日期。
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.TemporalAdjusters;

public class Main {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();

        // Temporal adjusters for adjusting the dates
        System.out.println("First date of this month= "
                + today.with(TemporalAdjusters.firstDayOfMonth()));
        LocalDate lastDayOfYear = today.with(TemporalAdjusters.lastDayOfYear());
        System.out.println("Last date of this year= " + lastDayOfYear);

        Period period = today.until(lastDayOfYear);
        System.out.println("Period Format= " + period);
        System.out.println("Months remaining in the year= " + period.getMonths());

    }
}