Java Date Time - ZonedDateTime truncatedTo(TemporalUnit unit) example








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

Syntax

truncatedTo has the following syntax.

public ZonedDateTime truncatedTo(TemporalUnit unit)

Example

The following example shows how to use truncatedTo.

import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
//  w  w  w. j a  v a 2  s  .c  o  m
public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.truncatedTo(ChronoUnit.YEARS);
    System.out.println(n);
  } 
}