LocalTime getMinute() method in Java

Java 8Object Oriented ProgrammingProgramming

The minute of the hour for a particular LocalTime can be obtained using the getMinute() method in the LocalTime class in Java. This method requires no parameters and it returns the minute of the hour in the range of 0 to 59.

A program that demonstrates this is given as follows

Example

 Live Demo

import java.time.*;
public class Demo {
   public static void main(String[] args) {
      LocalTime lt = LocalTime.parse("23:15:30");
      System.out.println("The LocalTime is: " + lt);
      System.out.println("The minute is: " + lt.getMinute());
   }
}

output

The LocalTime is: 23:15:30
The minute is: 15

Now let us understand the above program.

First the LocalTime is displayed. Then the minute of hour for the LocaTime is displayed using the getMinute() method. A code snippet that demonstrates this is as follows:

LocalTime lt = LocalTime.parse("23:15:30");
System.out.println("The LocalTime is: " + lt);
System.out.println("The minute is: " + lt.getMinute());
raja
Published on 26-Mar-2019 13:50:52
Advertisements