Close

Java Date Time - LocalTime.plusHours() Examples

Java Date Time Java Java API 


Class:

java.time.LocalTime

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

Method:

public LocalTime plusHours(long hoursToAdd)

Returns a copy of this LocalTime with the specified number of hours added.



Examples


package com.logicbig.example.localtime;

import java.time.LocalTime;

public class PlusHoursExample {

public static void main (String... args) {
LocalTime t = LocalTime.of(10, 2, 20);

LocalTime t2 = t.plusHours(15);
System.out.println(t2);

t2 = t.plusHours(100);
System.out.println(t2);


t2 = t.plusHours(-15);
System.out.println(t2);
}
}

Output

01:02:20
14:02:20
19:02:20




See Also