ADVERTISEMENT
ADVERTISEMENT

Java LocalDate Class | isSupported() Method with Example

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

LocalDate Class isSupported() method

Syntax:

public boolean isSupported (TemporalField t_field);
public boolean isSupported (TemporalUnit t_unit);
  • isSupported() method is available in java.time package.
  • isSupported (TemporalField t_field) method is used to check whether the given field is supported or not.
  • isSupported (TemporalUnit t_unit) method is used to identify whether the given unit is supported or not.
  • These methods don't throw an exception at the time of checking status.
  • These are non-static methods and it is accessible with class objects and if we try to access these methods with class name then we will get an error.

Parameter(s):

  • In the first cases, isSupported (TemporalField t_field),
    • TemporalField t_field – represents the field to be checked for support.
  • In the second cases, atStartOfDay(ZoneId zo),
    • TemporalUnit t_unit – represents the unit to be checked for support.

Return value:

In both the cases, the return type of the method is boolean,

  • In the first case, it returns true when the given field is supported otherwise it returns false.
  • In the second case, it returns true when the given unit is supported otherwise it returns false.

Example:

// Java program to demonstrate the example 
// of isSupported() method of LocalDate

import java.time.*;
import java.time.temporal.*;

public class IsSupportedOfLocalDate {
    public static void main(String args[]) {
        // Instantiates two LocalDate
        LocalDate l_da1 = LocalDate.parse("2007-04-04");
        LocalDate l_da2 = LocalDate.now();

        // Display l_da1,l_da2
        System.out.println("LocalDate l_da1 and l_da2: ");
        System.out.println("l_da1: " + l_da1);
        System.out.println("l_da2: " + l_da2);

        System.out.println();

        // Here, this method checks whether
        // the given field DAY_OF_WEEK is 
        // supported or not
        boolean status = l_da1.isSupported(ChronoField.DAY_OF_WEEK);

        // Display status
        System.out.println("l_da1.isSupported(ChronoField.DAY_OF_WEEK): " + status);

        // Here, this method checks whether
        // the given unit DECADES is supported
        // or not
        status = l_da2.isSupported(ChronoUnit.DECADES);

        // Display status
        System.out.println("l_da2.isSupported(ChronoUnit.DECADES): " + status);
    }
}

Output

LocalDate l_da1 and l_da2: 
l_da1: 2007-04-04
l_da2: 2020-06-03

l_da1.isSupported(ChronoField.DAY_OF_WEEK): true
l_da2.isSupported(ChronoUnit.DECADES): true
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.