Skip to content

Commit 57c345d

Browse files
committed
feat(datetime-api): add CalendarDemo showcasing GregorianCalendar usage
What - Added CalendarDemo under DateandTimeAPI package. - Demonstrates usage of java.util.GregorianCalendar. - Highlights key operations: - Checking leap years with isLeapYear(). - Retrieving today’s date, month, day of week, and day of month. - Printing the full GregorianCalendar object. Why - Provides a practical example of working with the legacy Calendar API. - Helps understand how GregorianCalendar handles common date/time queries. - Builds a foundation for comparing legacy APIs with modern java.time (introduced in Java 8). How to use - Run CalendarDemo. - Output will display: 1. Leap year check (true for 2020). 2. Current day of month (DATE). 3. Current month (0-based: January=0, December=11). 4. Day of the week (1=Sunday, 7=Saturday). 5. Current day of month again (DAY_OF_MONTH). 6. Complete calendar object with full internal state. Real-life applications - Scheduling events and checking leap years in scheduling software. - Payroll systems calculating month-end dates. - Banking/finance applications handling due dates and weekends. - Ticket booking systems validating weekdays and weekends. Notes - `Calendar.MONTH` is zero-based (January=0). - `Calendar.DAY_OF_WEEK` returns 1–7 with Sunday as 1. - GregorianCalendar is mutable and not thread-safe. - For modern applications, prefer `java.time` classes (LocalDate, LocalDateTime, ZonedDateTime). Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent be989a2 commit 57c345d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Section26DateandTimeAPI/Calendar/src/CalendarDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public static void main(String[] args) {
77
GregorianCalendar gc = new GregorianCalendar();
88

99
System.out.println(gc.isLeapYear(2020));
10-
1110
System.out.println("Today Date: "+gc.get(Calendar.DATE));
11+
1212
System.out.println(gc.get(Calendar.MONTH));
1313

1414
System.out.println(gc.get(Calendar.DAY_OF_WEEK));

0 commit comments

Comments
 (0)