Java LocalTime getHour() Method
Example
Get the hour of a time:
import java.time.LocalTime;
public class Main {
public static void main(String[] args) {
LocalTime myTime = LocalTime.of(14, 30);
System.out.println(myTime.getHour());
}
}
Definition and Usage
The getHour() method returns the hour of the time, as a number from 0 to 23 (the 24-hour clock).
Tip: Use the getMinute() method to get the minute.
Syntax
public int getHour()
Parameter Values
None.
Technical Details
| Returns: | The hour, from 0 to 23. |
|---|
Related Pages
❮ Date and Time Methods