Close

Java Date Time - OffsetTime.withSecond() Examples

Java Date Time Java Java API 


Class:

java.time.OffsetTime

java.lang.Objectjava.lang.Objectjava.time.OffsetTimejava.time.OffsetTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

public OffsetTime withSecond(int second)

Returns a copy of this OffsetTime with the second-of-minute replaced with the provided second.

If the provided 'second' is not valid, this method will throw java.time.DateTimeException. The valid values for second are 0 - 59.


Examples


package com.logicbig.example.offsettime;

import java.time.OffsetTime;

public class WithSecondExample {

public static void main(String... args) {
OffsetTime t = OffsetTime.now();
System.out.println(t);

OffsetTime t2 = t.withSecond(59);
System.out.println(t2);
}
}

Output

16:12:42.649-05:00
16:12:59.649-05:00




See Also