Java Language Calendar and its Subclasses Creating Calendar objects

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Calendar objects can be created by using getInstance() or by using the constructor GregorianCalendar.

It's important to notice that months in Calendar are zero based, which means that JANUARY is represented by an int value 0. In order to provide a better code, always use Calendar constants, such as Calendar.JANUARY to avoid misunderstandings.

Calendar calendar = Calendar.getInstance();
Calendar gregorianCalendar = new GregorianCalendar();
Calendar gregorianCalendarAtSpecificDay = new GregorianCalendar(2016, Calendar.JANUARY, 1);
Calendar gregorianCalendarAtSpecificDayAndTime = new GregorianCalendar(2016, Calendar.JANUARY, 1, 6, 55, 10);

Note: Always use the month constants: The numeric representation is misleading, e.g. Calendar.JANUARY has the value 0



Got any Java Language Question?