Skip to content

Commit 3df1606

Browse files
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

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

Section26DateandTimeAPI/src/TimeZoneDemo.java renamed to Section26DateandTimeAPI/Time/src/TimeZoneDemo.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ public static void main(String[] args) {
1414
gc.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
1515
TimeZone tz1 = gc.getTimeZone();
1616
System.out.println(tz1.getID());
17-
18-
1917
}
2018
}

0 commit comments

Comments
 (0)