Skip to content

Commit e978e51

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

1 file changed

+1
-0
lines changed

Section26DateandTimeAPI/src/DateandTimeAPI/DateTimeFormatDemo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void main(String[] args) {
1919
//S = milliseconds
2020
//z = time zone
2121
//Z = offset
22+
2223
LocalDateTime dt = LocalDateTime.now();
2324
DateTimeFormatter df = DateTimeFormatter.ofPattern("dd/MM/yyyy");
2425
System.out.println(df.format(dt));

0 commit comments

Comments
 (0)