ChronoPeriod negated() method in Java with Examples
The negated() method of ChronoPeriod interface in Java is used to return a new instance of ChronoPeriod after negating all the elements of the period YEAR, MONTH, DAY.
Syntax:
ChronoPeriod negated()
Parameters: This method does not accepts any parameter.
Return Value: This method returns a new instance of ChronoPeriod after negating each element of the period.
Exceptions: It throws an ArithmeticException. This exception is caught if numeric overflow occurs.
Below program illustrates the above method:
Program 1:
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.ChronoUnit;
public class ChronoPeriodClass {
static void toNegate(ChronoPeriod p1)
{
System.out.println(p1.negated());
}
public static void main(String[] args)
{
int year = 4 ;
int months = 11 ;
int days = 10 ;
ChronoPeriod p1 = Period.of(year, months, days);
toNegate(p1);
}
}
|
Program 2:
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.ChronoUnit;
public class ChronoPeriodClass {
static void toNegate(ChronoPeriod p1)
{
System.out.println(p1.negated());
}
public static void main(String[] args)
{
int year = - 4 ;
int months = - 11 ;
int days = - 10 ;
ChronoPeriod p1 = Period.of(year, months, days);
toNegate(p1);
}
}
|
Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoPeriod.html#negated–
Last Updated :
24 Jun, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...