Java Date Time - LocalTime getHour() example








LocalTime getHour() gets the hour-of-day field.

Syntax

getHour has the following syntax.

public int getHour()

Example

The following example shows how to use getHour.

import java.time.LocalTime;

public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.now();

    System.out.println(l.getHour());
  }
}

The code above generates the following result.