Sunday, October 19, 2025
HomeLanguagesJavaLocalTime getSecond() method in Java with Examples

LocalTime getSecond() method in Java with Examples

The getSecond() method of a LocalTime class is used to return the second-of-minute field. This method returns an integer value ranging from 0 to 59, i.e. the Seconds of a minute.

Syntax:

public int getSecond()

Parameters: This method does not accept any parameter.

Return value: This method returns an integer value which represents second-of-minute and it ranges from 0 to 59.

Below programs illustrate the getSecond() method:

Program 1:




// Java program to demonstrate
// LocalTime.getSecond() 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 Second field using getSecond()
        int Second = time.getSecond();
  
        // print result
        System.out.println("Second Field: "
                           + Second);
    }
}


Output:

Second Field: 50

Program 2:




// Java program to demonstrate
// LocalTime.getSecond() 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 Second field using getSecond()
        int Second = time.getSecond();
  
        // print result
        System.out.println("Second Field: "
                           + Second);
    }
}


Output:

Second Field: 30

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#getSecond()

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS