LocalTime getHour() method in Java with Examples
Last Updated :
03 Dec, 2018
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:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalTime time
= LocalTime.parse( "19:34:50.63" );
int Hour = time.getHour();
System.out.println( "Hour Field: "
+ Hour);
}
}
|
Program 2:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalTime time
= LocalTime.parse( "23:14:30.53" );
int Hour = time.getHour();
System.out.println( "Hour Field: "
+ Hour);
}
}
|
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#getHour()
Share your thoughts in the comments
Please Login to comment...