Java Date Time - OffsetDateTime now(ZoneId zone) example








OffsetDateTime now(ZoneId zone) creates the current date-time from the system clock in the specified time-zone.

Syntax

now has the following syntax.

public static OffsetDateTime now(ZoneId zone)

Example

The following example shows how to use now.

import java.time.OffsetDateTime;
import java.time.ZoneId;
//  w  w w  . j  a  v  a  2  s  .com
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now(ZoneId.systemDefault());
    
    System.out.println(o);
  }
}

The code above generates the following result.