LocalTime getHour() method in Java with Examples
The getHour() method of a LocalTime class is used to return the hour-of-day field. This method returns an integer value ranging from 0 to 23, i.e. the Hours of a day.
Syntax:
public int getHour()
Parameters: This method does not accept any parameter.
Return value: This method returns an integer value which represents hour-of-day and it ranges from 0 to 23.
Below programs illustrate the getHour() method:
Program 1:
// Java program to demonstrate // LocalTime.getHour() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time = LocalTime.parse("19:34:50.63"); // get Hour field using getHour() int Hour = time.getHour(); // print result System.out.println("Hour Field: " + Hour); } } |
Hour Field: 19
Program 2:
// Java program to demonstrate // LocalTime.getHour() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time = LocalTime.parse("23:14:30.53"); // get Hour field using getHour() int Hour = time.getHour(); // print result System.out.println("Hour Field: " + Hour); } } |
Hour Field: 23
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#getHour()
Recommended Posts:
- LocalDateTime getHour() method in Java with Examples
- OffsetTime getHour() method in Java with examples
- OffsetDateTime getHour() method in Java with examples
- ZonedDateTime getHour() method in Java with Examples
- LocalTime get() method in Java with Examples
- LocalTime with() Method in Java with Examples
- LocalTime until() Method in Java with Examples
- LocalTime from() method in Java with Examples
- LocalTime plus() method in Java with Examples
- LocalTime minus() method in Java with Examples
- LocalTime parse() method in Java with Examples
- LocalTime isSupported() method in Java with Examples
- LocalTime withHour() method in Java with Examples
- LocalTime withSecond() method in Java with Examples
- LocalTime withMinute() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



