本文整理汇总了Java中org.threeten.bp.ZonedDateTime.plusMonths方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.plusMonths方法的具体用法?Java ZonedDateTime.plusMonths怎么用?Java ZonedDateTime.plusMonths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.plusMonths方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchedule
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) {
ArgumentChecker.notNull(startDate, "start date");
ArgumentChecker.notNull(endDate, "end date");
ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date");
if (startDate.equals(endDate)) {
if (startDate.getDayOfMonth() == 1) {
return new ZonedDateTime[] {startDate};
}
throw new IllegalArgumentException("Start date and end date were the same but neither was the first day of the month");
}
final List<ZonedDateTime> dates = new ArrayList<>();
ZonedDateTime date = startDate.with(TemporalAdjusters.firstDayOfMonth());
if (date.isBefore(startDate)) {
date = date.plusMonths(1);
}
while (!date.isAfter(endDate)) {
dates.add(date);
date = date.plusMonths(1);
}
return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}
示例2: nextQuarter
import org.threeten.bp.ZonedDateTime; //导入方法依赖的package包/类
/**
* Moves the date to the next IMM quarter month (at least one month in the future). The returned date is the same date in the month as the initial date.
* @param date The reference date (as a ZonedDateTime).
* @return The date in the next quarterly month.
*/
public static ZonedDateTime nextQuarter(final ZonedDateTime date) {
ZonedDateTime result = date;
do {
result = result.plusMonths(1);
} while (!FUTURES_QUARTERS.contains(result.getMonth()));
return result;
}