Java Date Time Java Java API
java.time.OffsetDateTime
public OffsetDateTime minusHours(long hours)
Returns a copy of this OffsetDateTime with the specified number of hours subtracted, adjusting other fields if necessary.
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusHoursExample { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2016, 10, 3, 14, 30), ZoneOffset.of("-5")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusHours(8); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusHours(200); System.out.println(offsetDateTime2); }}
2016-10-03T14:30-05:002016-10-03T06:30-05:002016-09-25T06:30-05:00
package com.logicbig.example.offsetdatetime;import java.time.LocalDateTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class MinusHoursExample2 { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2016, 10, 3, 14, 30), ZoneOffset.of("-5")); System.out.println(d); OffsetDateTime offsetDateTime = d.minusHours(-8); System.out.println(offsetDateTime); OffsetDateTime offsetDateTime2 = d.minusHours(-200); System.out.println(offsetDateTime2); }}
2016-10-03T14:30-05:002016-10-03T22:30-05:002016-10-11T22:30-05:00