Returns a copy of this year with the specified temporal amount added.
Returns a copy of this year with the specified amount for the specified temporal unit added.
package com.logicbig.example.year;
import java.time.DateTimeException;
import java.time.Year;
import java.time.temporal.ChronoUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
public class PlusExample2 {
public static void main(String... args) {
Year y = Year.of(2017);
System.out.println(y);
for (ChronoUnit chronoUnit : ChronoUnit.values()) {
try {
Year y2 = y.plus(1, chronoUnit);
System.out.printf("%10s: %s%n", chronoUnit.name(), y2);
} catch (UnsupportedTemporalTypeException e) {
System.out.printf("%10s: not supported%n", chronoUnit.name());
} catch (Exception e){
System.out.printf("%10s: error: %s%n", chronoUnit.name(), e.getMessage());
}
}
}
}
Output
2017
NANOS: not supported
MICROS: not supported
MILLIS: not supported
SECONDS: not supported
MINUTES: not supported
HOURS: not supported
HALF_DAYS: not supported
DAYS: not supported
WEEKS: not supported
MONTHS: not supported
YEARS: 2018
DECADES: 2027
CENTURIES: 2117
MILLENNIA: 3017
ERAS: error: Invalid value for Era (valid values 0 - 1): 2
FOREVER: not supported