Java Date Time - LocalTime truncatedTo(TemporalUnit unit) example








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

Syntax

truncatedTo has the following syntax.

public LocalTime truncatedTo(TemporalUnit unit)

Example

The following example shows how to use truncatedTo.

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
//  w  w  w .jav a  2 s .  c o  m
public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.now();
    LocalTime s = l.truncatedTo(ChronoUnit.HOURS);
    System.out.println(s);
  }
}

The code above generates the following result.