Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/compat.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-meta-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/l10n.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-walker.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-walker.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-date-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/theme.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-user-query.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/revision.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/revision.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/category.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/category.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/comment-template.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/comment-template.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-rewrite.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/kses.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/kses.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class.wp-dependencies.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/functions.wp-scripts.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/functions.wp-scripts.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/update.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/canonical.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-http.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/admin-bar.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/admin-bar.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-block-parser.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/class-wp-block-parser.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1

Notice: Uninitialized string offset: 0 in /home/ebullite/candidjava.com/wp-includes/widgets/class-wp-widget-media-image.php on line 1
How to get Year Month Date from Calendar Object in Java
Date and Time

How to get Year Month Date from Calendar Object in Java

Table of Contents

Program

import java.util.Calendar;
import java.util.Date;

public class DateToCalendar
{
	public static void main(String[] args) 
	{
		Date date = new Date();	
		System.out.println("Java Date & Time:" + date);
		Calendar cal = Calendar.getInstance();
		System.out.println("Calendar Present Year : " + cal.get(Calendar.YEAR));
		System.out.println("Calendar Present Date : " + cal.get(Calendar.DATE));
		System.out.println("Calendar Month : " + cal.get(Calendar.MONTH));	
	}
}

Output

	Java Date & Time:Mon Apr 12 11:20:52 IST 2021
	Calendar Present Year : 2021
	Calendar Present Date : 12
	Calendar Month : 4

Description

public abstract class Calendar

Qextends Object
implements Serializable, Cloneable, Comparable
The Calendar class is an abstract class that provides methods for converting between a specific instant in
time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating
the calendar fields, such as getting the date of the next week. An instant in time can be represented by a
millisecond value that is an offset from the Epoch, January 1, 1970, 00:00:00.000 GMT (Gregorian).
The class also provides additional fields and methods for implementing a concrete calendar system outside the
package. Those fields and methods are defined as protected.
Like other locale-sensitive classes, Calendar provides a class method, getInstance, for getting a generally
useful object of this type. Calendar’s getInstance method returns a Calendar object whose calendar fields have
been initialized with the current date and time:
Calendar rightNow = Calendar.getInstance();
A Calendar object can produce all the calendar field values needed to implement the date-time formatting for a
particular language and calendar style (for example, Japanese-Gregorian, Japanese-Traditional). Calendar defines the
range of values returned by certain calendar fields, as well as their meaning. For example, the first month of the
calendar system has the value MONTH == JANUARY for all calendars. Other values are defined by the concrete subclass, such
as ERA. See individual field documentation and subclass documentation for details.