ZonedDateTime truncatedTo(TemporalUnit unit) example

Description

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  .ja  va 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);
  } 
}




















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset