Java LocalDateTime Class | getMinute() Method with Example

LocalDateTime Class getMinute() method: Here, we are going to learn about the getMinute() method of LocalDateTime Class with its syntax and example.
Submitted by Preeti Jain, on June 06, 2020

LocalDateTime Class getMinute() method

  • getMinute() method is available in java.time package.
  • getMinute() method is used to get minute-of-hour field value from this date-time object.
  • getMinute() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getMinute() method does not throw an exception at the time of getting a minute of the hour.

Syntax:

    public int getMinute();

Parameter(s):

  • None

Return value:

The return type of this method is int, it returns the value minute-of-hour field from this object and the number of minutes in an hour starts from 0 and ends at 59.

Example:

// Java program to demonstrate the example 
// of getMinute() method of LocalDateTime

import java.time.*;

public class GetMinuteOfLocalDateTime {
    public static void main(String args[]) {
        // Instantiates two LocalDateTime
        LocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10");
        LocalDateTime da_ti2 = LocalDateTime.now();

        // Display da_ti1, da_ti2
        System.out.println("LocalDateTime da_ti1 and da_ti2: ");
        System.out.println("da_ti1: " + da_ti1);
        System.out.println("da_ti2: " + da_ti2);

        System.out.println();

        // Here, this method returns the field
        // value minute-of-hour from this date-time
        // object (da_ti1)
        int get_min = da_ti1.getMinute();

        // Display get_min
        System.out.print("da_ti1.getMinute(): ");
        System.out.println(get_min);

        // Here, this method returns the field
        // value minute-of-hour from this date-time
        // object (da_ti2)
        get_min = da_ti2.getMinute();

        // Display get_min
        System.out.print("da_ti2.getMinute(): ");
        System.out.println(get_min);
    }
}

Output

LocalDateTime da_ti1 and da_ti2: 
da_ti1: 2005-10-05T10:10:10
da_ti2: 2020-06-05T03:09:28.475235

da_ti1.getMinute(): 10
da_ti2.getMinute(): 9


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.