- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 isSupported() method in Java
It can be checked if a ChronoUnit is supported by the LocalTime class or not by using the isSupported() method in the LocalTime class in Java. This method requires a single parameter i.e. the ChronoUnit to check. It returns true if the ChronoUnit is supported by the LocalTime class and false otherwise.
A program that demonstrates this is given as follows −
Example
import java.time.*; import java.time.temporal.*; public class Demo { public static void main(String[] args) { LocalTime lt = LocalTime.now(); System.out.println("The LocalTime is: " + lt); boolean flag = lt.isSupported(ChronoUnit.HOURS); if(flag) System.out.println("The ChronoUnit HOURS is supported"); else System.out.println("The ChronoUnit HOURS is not supported"); } }
Output
The LocalTime is: 07:09:42.262 The ChronoUnit HOURS is supported
Now let us understand the above program.
First the current LocalTime object is displayed. Then the isSupported() method is used to check if the ChronoUnit HOURS is supported by the LocalTime class or not. The returned value is stored in flag and the appropriate response is printed. A code snippet that demonstrates this is as follows −
LocalTime lt = LocalTime.now(); System.out.println("The LocalTime is: " + lt); boolean flag = lt.isSupported(ChronoUnit.HOURS); if(flag) System.out.println("The ChronoUnit HOURS is supported"); else System.out.println("The ChronoUnit HOURS is not supported");
Advertisements