
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LocalTime get Method in Java
The value of the specified field from the LocalTime can be obtained using the get() method in the LocalTime class in Java. This method requires a single parameter i.e. ChronoField that is required and it returns the value of the specified field from the LocalTime.
A program that demonstrates this is given as follows
Example
import java.time.*; import java.time.temporal.ChronoField; public class Main{ 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_OF_HOUR is: " + lt.get(ChronoField.MINUTE_OF_HOUR)); } }
output
The LocalTime is: 23:15:30 The MINUTE_OF_HOUR is: 15
Now let us understand the above program.
First the LocalTime object is displayed. Then the value of the ChronoField MINUTE_OF_HOUR from the LocalTime object is obtained using the get() method and printed. 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_OF_HOUR is: " + lt.get(ChronoField.MINUTE_OF_HOUR));
Advertisements