TemporalAdjusters类的lastDayOfYear()方法用于返回“一年中的最后一天” TemporalAdjuster对象,该对象将返回设置为一年中最后一天的新Date对象。
用法:
public static TemporalAdjuster lastDayOfYear()
参数:此方法不接受任何内容。
返回值:此方法返回年份调整器的最后一天,而不是null。
以下示例程序旨在说明TemporalAdjusters.lastDayOfYear()方法:
程序1:
// Java program to demonstrate
// TemporalAdjusters.lastDayOfYear()
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
public class GFG {
public static void main(String[] args)
{
// get TemporalAdjuster with last day
// of the year adjuster
TemporalAdjuster temporalAdjuster
= TemporalAdjusters.lastDayOfYear();
// using adjuster for local date time
LocalDate localDate
= LocalDate.of(2023, 10, 11);
LocalDate lastDayOfYear
= localDate.with(temporalAdjuster);
// print
System.out.println("last day of the "
+ "year for localdate "
+ localDate + ":"
+ lastDayOfYear);
}
}
输出:
last day of the year for localdate 2023-10-11:2023-12-31
程序2:
// Java program to demonstrate
// TemporalAdjusters.lastDayOfYear() method
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
public class GFG {
public static void main(String[] args)
{
// get TemporalAdjuster with last day
// of year adjuster
TemporalAdjuster temporalAdjuster
= TemporalAdjusters.lastDayOfYear();
// using adjuster for local date time
LocalDate localDate
= LocalDate.of(2099, 12, 29);
LocalDate lastDayOfYear
= localDate.with(temporalAdjuster);
// print
System.out.println("last day of "
+ "year for localdate "
+ localDate + ":"
+ lastDayOfYear);
}
}
输出:
last day of year for localdate 2099-12-29:2099-12-31
参考文献:https://docs.oracle.com/javase/10/docs/api/java/time/format/TemporalAdjusters.html
相关用法
- Java TemporalAdjusters next()用法及代码示例
- Java TemporalAdjusters firstDayOfNextYear()用法及代码示例
- Java TemporalAdjusters lastInMonth()用法及代码示例
- Java TemporalAdjusters firstDayOfNextMonth()用法及代码示例
- Java TemporalAdjusters firstDayOfMonth()用法及代码示例
- Java TemporalAdjusters nextOrSame()用法及代码示例
- Java TemporalAdjusters firstInMonth()用法及代码示例
- Java TemporalAdjusters previous()用法及代码示例
- Java TemporalAdjusters previousOrSame()用法及代码示例
- Java TemporalAdjusters firstDayOfYear()用法及代码示例
- Java TemporalAdjusters lastDayOfMonth()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 TemporalAdjusters lastDayOfYear() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。