Java Date Time - OffsetDateTime minus(TemporalAmount amountToSubtract) example








OffsetDateTime minus(TemporalAmount amountToSubtract) returns a copy of this date-time with the specified amount subtracted.

Syntax

minus has the following syntax.

public OffsetDateTime minus(TemporalAmount amountToSubtract)

Example

The following example shows how to use minus.

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
//from   w  w w.  ja  va  2s  . c o  m
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.