Period isNegative() example

Description

Period isNegative() checks if any of the three units of this period are negative.

Syntax

isNegative has the following syntax.


public boolean isNegative()

Example

The following example shows how to use isNegative.


import java.time.Period;
/*  w w  w .  j  a  v  a2 s  .  c  o  m*/
public class Main {
  public static void main(String[] args) {
    Period p = Period.ofMonths(1);
    
    System.out.println(p.isNegative());

  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset