Commit e978e51
committed
feat(datetime-api): add DateTimeFormatDemo showcasing custom date-time formatting
What
- Introduced DateTimeFormatDemo under DateandTimeAPI package.
- Demonstrates use of DateTimeFormatter with LocalDateTime and ZonedDateTime.
- Added multiple formatting patterns:
- "dd/MM/yyyy" → formats date only (day/month/year).
- "dd/MM/yyyy hh:mm:ss" → adds time in 12-hour format.
- "dd/MM/yyyy hh:mm:ss z" → includes time zone abbreviation using ZonedDateTime.
Why
- Provides clear examples of formatting temporal objects using patterns.
- Shows how different symbols (y, M, d, h, H, m, s, S, z, Z) control output formatting.
- Reinforces distinction between LocalDateTime (no timezone) and ZonedDateTime (timezone aware).
How to use
- Run DateTimeFormatDemo.
- Output will display:
1. Current system date in dd/MM/yyyy.
2. Current system date + time in dd/MM/yyyy hh:mm:ss.
3. Current zoned date-time including timezone (e.g., IST, PST).
Real-life applications
- Formatting timestamps in logging frameworks.
- Displaying human-readable dates in UIs, reports, or invoices.
- Parsing/printing ISO or custom date formats in APIs.
- Handling time zones for global applications.
Notes
- `hh` prints 12-hour format; use `HH` for 24-hour.
- `z` gives short timezone name (e.g., IST), `Z` gives numeric offset (e.g., +0530).
- Thread-safe: DateTimeFormatter is immutable and safe for concurrent use.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 6aa6105 commit e978e51
File tree
1 file changed
+1
-0
lines changed- Section26DateandTimeAPI/src/DateandTimeAPI
1 file changed
+1
-0
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
0 commit comments