Commit 314f06a
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 e978e51 commit 314f06a
File tree
1 file changed
+34
-16
lines changed- Section26DateandTimeAPI/src/DateandTimeAPI
1 file changed
+34
-16
lines changedLines changed: 34 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | 5 | | |
21 | 6 | | |
| 7 | + | |
22 | 8 | | |
| 9 | + | |
| 10 | + | |
23 | 11 | | |
| 12 | + | |
| 13 | + | |
24 | 14 | | |
| 15 | + | |
| 16 | + | |
25 | 17 | | |
| 18 | + | |
| 19 | + | |
26 | 20 | | |
| 21 | + | |
| 22 | + | |
27 | 23 | | |
| 24 | + | |
| 25 | + | |
28 | 26 | | |
29 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
0 commit comments