Java Date Time Java Java API
java.time.LocalDateTime
public LocalDateTime withSecond(int second)
Returns a copy of this LocalDateTime with the second-of-minute field replaced with the specified
second value. This method will throw exception for an invalid value e.g. values greater than 60.
package com.logicbig.example.localdatetime;import java.time.LocalDateTime;public class WithSecondExample { public static void main (String... args) { LocalDateTime d = LocalDateTime.of(2000, 1, 2, 10, 20, 30, 2000); System.out.println(d); LocalDateTime d2 = d.withSecond(50); System.out.println(d2); }}
2000-01-02T10:20:30.0000022000-01-02T10:20:50.000002