Returns a copy of this year-month with the specified amount of the specified unit subtracted.
package com.logicbig.example.yearmonth;
import java.time.Period;
import java.time.YearMonth;
public class MinusExample {
public static void main(String... args) {
YearMonth y = YearMonth.of(2010, 11);
System.out.println(y);
Period p = Period.ofYears(100);
System.out.println(p);
YearMonth y2 = y.minus(p);
System.out.println(y2);
Period p2 = Period.ofYears(-100);
System.out.println(p2);
YearMonth y3 = y.minus(p2);
System.out.println(y3);
}
}
Output
2010-11
P100Y
1910-11
P-100Y
2110-11
package com.logicbig.example.yearmonth;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
public class MinusExample2 {
public static void main(String... args) {
YearMonth y = YearMonth.of(2010, 11);
System.out.println(y);
for (ChronoUnit chronoUnit : ChronoUnit.values()) {
try {
YearMonth d2 = y.minus(1, chronoUnit);
System.out.printf("%10s: %s%n", chronoUnit.name(), d2);
} catch (UnsupportedTemporalTypeException e) {
System.out.printf("%10s: not supported%n", chronoUnit.name());
}
}
}
}
Output
2010-11
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: 2010-10
YEARS: 2009-11
DECADES: 2000-11
CENTURIES: 1910-11
MILLENNIA: 1010-11
ERAS: -2009-11
FOREVER: not supported