Calendar.isSet()

Date

Calendar.isSet(field) Check if the field value is set or not.

field : Required Calendar field, Year, month , date, hour , minute , second .
Returns value is boolean, returns true if field value is set , false otherwise.

Examples with output
Let us create one calendar object and we will check the fields by using isSet().
package my_proj;
 
import java.util.Calendar;
 
public class my_first {
public static void main(String[] args) {

Calendar my_cal = Calendar.getInstance();// created calendar 

System.out.println(my_cal.isSet(Calendar.YEAR));// true
my_cal.clear(Calendar.YEAR); // Clear or reset the year part 
System.out.println(my_cal.isSet(Calendar.YEAR));// false
System.out.println(my_cal.isSet(Calendar.MONTH));// true 

}
}
Here we have first checked for YEAR by using isSet() and the value we got is true. Then we reset the value by using clear() and then isSet() reutned false. However clear() has not removed the other field values so we got true when we checked for the field MONTH in last line.

By resetting or clearing HOUR field we are not resetting HOUR_OF_DAY. Check this code with output.
package my_proj;
 
import java.util.Calendar;
 
public class my_first {
public static void main(String[] args) {

Calendar my_cal = Calendar.getInstance();// created calendar 

System.out.println(my_cal.isSet(Calendar.YEAR));// true
my_cal.clear(Calendar.HOUR);
System.out.println(my_cal.isSet(Calendar.HOUR));// false
System.out.println(my_cal.isSet(Calendar.HOUR_OF_DAY));// true 
System.out.println(my_cal.get(Calendar.HOUR_OF_DAY)); // 14

}
}
clear() Date & time tutorials


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer