Java Date Time - OffsetDateTime truncatedTo(TemporalUnit unit) example








OffsetDateTime truncatedTo(TemporalUnit unit) returns a copy of this OffsetDateTime with the time truncated.

Syntax

truncatedTo has the following syntax.

public OffsetDateTime truncatedTo(TemporalUnit unit)

Example

The following example shows how to use truncatedTo.

import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
/*  w w w.  j a v a  2  s . co m*/
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.truncatedTo(ChronoUnit.DAYS);
    System.out.println(d);
  }
}

The code above generates the following result.