- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - Month
- java.time 有用資源
- java.time - 討論
java.time.YearMonth.with() 方法示例
描述
java.time.YearMonth.with(TemporalAdjuster adjuster) 方法返回此年份的一個調整後的副本。
宣告
以下是 java.time.YearMonth.with(TemporalAdjuster adjuster) 方法的宣告。
public YearMonth with(TemporalAdjuster adjuster)
引數
adjuster - 要使用的調整程式,不能為空。
返回值
a YearMonth 基於此月份,已進行調整,不能為空。
異常
DateTimeException - 如果無法進行調整。
ArithmeticException - 如果發生數字溢位。
示例
以下示例演示了 java.time.YearMonth.with(TemporalAdjuster adjuster) 方法的用法。
package com.tutorialspoint;
import java.time.YearMonth;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.parse("2017-12");
YearMonth result = date.with(YearMonth.of(2010,12));
System.out.println(result);
}
}
讓我們編譯並執行以上程式,這將產生以下結果 -
2010-12
廣告