TemporalAdjusters类的next(DayOfWeek)方法用于返回下一个day-of-week TemporalAdjuster对象,该对象可用于获取新的Date对象,该对象是具有相同匹配DayOfWeek的下一个日期,该日期作为参数从任何Date对象上传递将应用此TempotralAdjuster。
用法:
public static TemporalAdjuster next(DayOfWeek dayOfWeek)
参数:此方法接受dayOfWeek,可用于获取新的Date对象,该对象是具有相同匹配的DayOfWeek的下一个日期。
返回值:此方法返回星期几的第二天,而不是null。
以下示例程序旨在说明TemporalAdjusters.next()方法:
程序1:
// Java program to demonstrate
// TemporalAdjusters.next()
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
// get TemporalAdjuster with
// the next in month adjuster
TemporalAdjuster temporalAdjuster
= TemporalAdjusters.next(
DayOfWeek.WEDNESDAY);
// using adjuster for local date time
LocalDate localDate
= LocalDate.of(1998, 10, 31);
LocalDate nextDOW
= localDate.with(temporalAdjuster);
// print
System.out.println(
"next day of the week having"
+ " WEDNESDAY for localdate "
+ localDate + " is:"
+ nextDOW);
}
}
输出:
next day of the week having WEDNESDAY for localdate 1998-10-31 is:1998-11-04
程序2:
// Java program to demonstrate
// TemporalAdjusters.next() method
import java.time.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] args)
{
// get TemporalAdjuster with the
// next day of week adjuster
TemporalAdjuster temporalAdjuster
= TemporalAdjusters.next(
DayOfWeek.THURSDAY);
// using adjuster for local date time
LocalDate localDate
= LocalDate.of(2029, 12, 11);
LocalDate nextDOW
= localDate.with(temporalAdjuster);
// print
System.out.println(
"next day of the week having"
+ " THURSDAY for localdate "
+ localDate + " is:"
+ nextDOW);
}
}
输出:
next day of the week having THURSDAY for localdate 2029-12-11 is:2029-12-13
相关用法
- Java TemporalAdjusters nextOrSame()用法及代码示例
- Java TemporalAdjusters firstInMonth()用法及代码示例
- Java TemporalAdjusters firstDayOfNextYear()用法及代码示例
- Java TemporalAdjusters lastInMonth()用法及代码示例
- Java TemporalAdjusters firstDayOfNextMonth()用法及代码示例
- Java TemporalAdjusters firstDayOfMonth()用法及代码示例
- Java TemporalAdjusters previous()用法及代码示例
- Java TemporalAdjusters firstDayOfYear()用法及代码示例
- Java TemporalAdjusters lastDayOfMonth()用法及代码示例
- Java TemporalAdjusters lastDayOfYear()用法及代码示例
- Java TemporalAdjusters previousOrSame()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 TemporalAdjusters next() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。