OffsetDateTime withHour(int hour) example

Description

OffsetDateTime withHour(int hour) returns a copy of this OffsetDateTime with the hour-of-day value altered.

Syntax

withHour has the following syntax.


public OffsetDateTime withHour(int hour)

Example

The following example shows how to use withHour.


import java.time.OffsetDateTime;
//from www  .  j  a v a 2s.  c o m
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d =  o.withHour(4);
    System.out.println(d);
  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset