Java Date Time - OffsetDateTime withSecond(int second) example








OffsetDateTime withSecond(int second) returns a copy of this OffsetDateTime with the second-of-minute value altered.

Syntax

withSecond has the following syntax.

public OffsetDateTime withSecond(int second)

Example

The following example shows how to use withSecond.

import java.time.OffsetDateTime;

public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.withSecond(34);
    System.out.println(d);
  }
}

The code above generates the following result.