Close

Java Date Time - YearMonth.minusYears() Examples

Java Date Time Java Java API 


Class:

java.time.YearMonth

java.lang.Objectjava.lang.Objectjava.time.YearMonthjava.time.YearMonthjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public YearMonth minusYears(long yearsToSubtract)

Returns a copy of this YearMonth with the specified number of years subtracted.


Examples


package com.logicbig.example.yearmonth;

import java.time.YearMonth;

public class MinusYearsExample {

public static void main(String... args) {
YearMonth y = YearMonth.of(2010, 11);
System.out.println(y);

YearMonth y2 = y.minusYears(6);
System.out.println(y2);

YearMonth y3 = y.minusYears(-200);
System.out.println(y3);
}
}

Output

2010-11
2004-11
2210-11




See Also