Java Date Time - Instant truncatedTo(TemporalUnit unit) example








Instant truncatedTo(TemporalUnit unit) returns a copy of this Instant truncated to the specified unit.

Syntax

truncatedTo has the following syntax.

public Instant truncatedTo(TemporalUnit unit)

Example

The following example shows how to use truncatedTo.

import java.time.Instant;
import java.time.temporal.ChronoUnit;
/* w ww .  ja va  2  s  .  co  m*/
public class Main {
  public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    instant = instant.truncatedTo(ChronoUnit.DAYS);
    System.out.println(instant);
 
  }
}

The code above generates the following result.