Java Date Time - ZonedDateTime getOffset() example








ZonedDateTime getOffset() gets the zone offset, such as '+01:00'. This is the offset of the local date-time from UTC/Greenwich.

Syntax

getOffset has the following syntax.

public ZoneOffset getOffset()

Example

The following example shows how to use getOffset.

import java.time.ZonedDateTime;

public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime =ZonedDateTime.now();

    System.out.println(dateTime.getOffset());
  } 
}

The code above generates the following result.