Commit 57c345d
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
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments