Commit 3df1606
committed
feat(datetime-api): add TimeZoneDemo to explore java.util.TimeZone with GregorianCalendar
What
- Introduced `TimeZoneDemo` class demonstrating integration of `GregorianCalendar` with `TimeZone`.
- Showcases:
- Retrieving the system’s default time zone via `gc.getTimeZone()`.
- Printing display name and ID of the active zone.
- Switching calendar context to a different zone (`America/Los_Angeles`).
- Verifying changes by fetching the updated zone ID.
Why
- Time zone handling is critical for globalized applications where scheduling, logging, or transactions span multiple regions.
- Provides a clear, hands-on example of manipulating `TimeZone` objects with legacy `Calendar` APIs.
- Reinforces the difference between default system zones and programmatically set zones.
How to use
- Run `TimeZoneDemo` to view:
1. Default system time zone.
2. Human-readable display name.
3. Time zone ID string.
4. Updated ID after switching to Los Angeles.
- Modify the `TimeZone.getTimeZone("...")` argument to test with other region identifiers.
Real-life applications
- Converting timestamps between client and server time zones.
- Handling daylight savings adjustments.
- Supporting global applications (meetings, reservations, financial settlements).
- Useful when migrating legacy code using `Calendar`/`TimeZone` before moving to modern `java.time.ZonedDateTime`.
Notes
- `java.util.TimeZone` and `GregorianCalendar` are legacy but still widely used in older systems.
- Prefer modern `java.time` (`ZoneId`, `ZonedDateTime`) for new projects for immutability and thread-safety.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 0377805 commit 3df1606
1 file changed
+0
-2
lines changedLines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | 17 | | |
20 | 18 | | |
0 commit comments