Java Date Time - LocalDateTime withSecond(int second) example








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

Syntax

withSecond has the following syntax.

public LocalDateTime withSecond(int second)

Example

The following example shows how to use withSecond.

import java.time.LocalDateTime;
/*from   w  ww.  ja va  2  s .  c om*/
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);
    
    LocalDateTime t = a.withSecond(1234);
    
    System.out.println(t);
  }
}