Clock withZone(ZoneId zone) example

Description

Clock withZone(ZoneId zone) returns a copy of this clock with a different time-zone.

Syntax

withZone has the following syntax.


public abstract Clock withZone(ZoneId zone)

Example

The following example shows how to use withZone.


import java.time.Clock;
import java.time.ZoneId;
//w  ww. j  a  va2s . c  o m
public class Main {
  public static void main(String[] args) {
    Clock clock = Clock.systemUTC();
    System.out.println(clock.getZone());
    clock.withZone(ZoneId.systemDefault());
    
    System.out.println(clock.getZone());
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




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