Java Date Time - OffsetDateTime minus(long amountToSubtract, TemporalUnit unit) example








OffsetDateTime minus(long amountToSubtract, TemporalUnit unit) returns a copy of this date-time with the specified amount subtracted.

Syntax

minus has the following syntax.

public OffsetDateTime minus(long amountToSubtract,   TemporalUnit unit)

Example

The following example shows how to use minus.

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
/*from  w  w w  .  j  a v  a2s  .  c om*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.minus(20,ChronoUnit.HOURS);
    System.out.println(d);
  }
}

The code above generates the following result.