-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD5-5.txt
71 lines (54 loc) · 2.3 KB
/
D5-5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.time.format.DateTimeFormatter;
class Demonstrator
{
public static void main (String[] args) {
//ZonedDateTime is used to change the time according to zones
System.out.println("*****ZonedDateTime******");
System.out.println("ZonedDateTime Now: "+ZonedDateTime.now());
System.out.println("ZonedDateTime Europe: "+ZonedDateTime.now(ZoneId.of("Europe/Athens")));
//Period
System.out.println();
System.out.println("*****Period*****");
LocalDate present = LocalDate.now();
LocalDate later = present.plusDays(3);
Period period = Period.between(present, later);
int lops = period.getDays();
System.out.println("Difference in days: "+lops);
//ChronoUnit
System.out.println();
System.out.println("*****ChronoUnit*****");
LocalDate today = LocalDate.now();
System.out.println("Today's date: "+today);
LocalDate after = today.plus(1,ChronoUnit.MONTHS);
System.out.println("Date after 1 month: "+after);
//DateTimeFormatter
System.out.println();
System.out.println("*****DateTimeFormatter*****");
LocalDate paySlipDate = LocalDate.now();
System.out.println(paySlipDate); // Output: Current Date
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MMM/yyyy");
System.out.println(paySlipDate.format(formatter)); // Output: Current Date
}
}
Tryout:ZonedDateTime, Period, ChronoUnit and DateTimeFormatter .
Problem Statement
To demonstrate the working of ZonedDateTime, Period, ChronoUnit and DateTimeFormatter classes
Code in Java
Execution Result
Output:
*****ZonedDateTime******
ZonedDateTime Now: 2023-12-22T15:12:09.327+05:30[Asia/Kolkata]
ZonedDateTime Europe: 2023-12-22T11:42:09.331+02:00[Europe/Athens]
*****Period*****
Difference in days: 3
*****ChronoUnit*****
Today's date: 2023-12-22
Date after 1 month: 2024-01-22
*****DateTimeFormatter*****
2023-12-22
22/Dec/2023