Java Date Time - Clock withZone(ZoneId zone) example








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;
/*www  .  j  av  a2s.  co 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.