Java Calendar set() Method3 Nov 2024 | 2 min read The set() method of Calendar class is used to set the specified calendar field by the specified value. SyntaxThis method is overloaded in the following ways. Parameterfield - the calendar field. Value ? this passed value is set to specified calendar field as the parameter. ReturnsNA ThrowsNA Example 1Output: Today :Tue Aug 14 17:53:46 PDT 2018 Year :2018 Month :7 Day :3 Now Today :Sun Jun 23 10:15:20 PDT 1996 Now Year :1996 Now Month :5 Now Day :1 Example 2Output: Today :Tue Aug 14 17:58:18 PDT 2018 Altered Date(1) :Wed Aug 14 17:58:18 PDT 1996 Altered Date (2) :Wed Oct 23 17:58:18 PDT 1996 |
The getTimeZone() method of java.util.Calendar class gets the TimeZone of calendar object and returns a TimeZone object. Syntax public TimeZone getTimeZone() Parameter No parameter is passed. Returns Returns the TimeZone object. Throws Does not throw an exception. Example 1 import java.util.Calendar; import java.util.TimeZone; public class JavaCalendargetTimeZoneExample1 { public static void main(String[] args) { Calendar mycal = Calendar.getInstance(); ...
1 min read
The equals() method compares two objects for equality and returns true if they are equal. The equals() method is provided in the Object class. As object class is the super class of all other classes in java. Calendar class inherits the equals() method. It compares this...
3 min read
The setTimeInMillis () method of java.util.Calendar class is used to set the current time in millisecond. The date value to be set is passed as long into this method. Syntax public void setTimeInMillis(long millis) Parameter millis - the new time in UTC milliseconds. Returns Does not return value. Throws Does not throw Exception. Example 1 import...
2 min read
This method returns true if the time represented by this Calendar is after the time represented by when Object. If it is not the case, false is returned. Syntax Public boolean after (Object when) Parameter When - the Object of time that is about to be compared. Returns True if the time...
4 min read
The getMinimalDaysInFirstWeek() method returns required minimum days in integer form. The minimal days required in the first week of the year is passed into this method. Syntax public int getMinimalDaysInFirstWeek() Parameter No parameter is passed. Returns Returns an integer value which is minimum days required in first week. Throws Does not throw...
2 min read
The compareTo() method of Calendar class compares the time values (millisecond offsets) between two calendar object. Syntax public int compareTo(Calendar anotherCalendar) Parameter anotherCalendar - the Calendar object to be compared. Returns Returns an integer value either 0 , 1 or -1 Throws NullPointerException - if the specified Calendar is null. IllegalArgumentException - if the...
3 min read
The internalGet() method of java.util.Calendar class is a final, and protected method. This method returns the value of the calendar field passed as a parameter. Syntax protected final int internalGet(int field) Parameter field - the given calendar field. Returns the value for the given calendar field. Throws Does not throw Exception. Example 1 import java.util.GregorianCalendar; public class...
2 min read
The getAvailableCalendarTypes() method of java.util.Calendar class returns a Set which contains string set of all available calendar type supported by java Runtime Environment. It either returns calendar type or class name of calendar. Syntax public String getCalendarType() Parameter No parameter is passed to this method. Returns Returns the calendar type or class...
1 min read
The isLenient() method of Calendar class returns the Boolean value true if the interpretation mode of this calendar is lenient; false otherwise. Syntax Public boolean isLenient() Parameter No parameter is passed. Returns Returns Boolean value. Throws Does not throw Exception. Example 1 import java.util.*; public class JavaCalendarisLenintExample1 { public static void main(String[] args) { ...
2 min read
The SetFirstDayOfWeek() method of Calendar class is used to set the first day of the week. The value which is to be set as the first day of the week is passed as the parameter. Syntax public void setFirstDayOfWeek(int value) Parameter value - It is to be set as the...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India