-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD5-4.txt
53 lines (45 loc) · 2.57 KB
/
D5-4.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
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;
class Demonstrator
{
public static void main (String[] args) {
System.out.println("*****LocalDate*****");
LocalDate registrationDate = LocalDate.now(); //Creates an object with system date
System.out.println("Today's date(System date): "+registrationDate);
LocalDate lastDate = registrationDate.plusDays(3); // Adding 3 days to the registration date
System.out.println("Adding 3 days: "+lastDate);
if(LocalDate.now().isBefore(lastDate)) { // Checking whether current date is before the last date
System.out.println("Please take the assessment as soon as possible");
}
System.out.println();
System.out.println("*****LocalTime*****");
LocalTime startTime = LocalTime.now(); //Creates an object with system time
System.out.println("Start Time: "+startTime); //The time being returned here is according to the region/locale/zone in which the application is hosted.
LocalTime endTime = startTime.plusHours(1); //Adding 1 hour
System.out.println("End Time: "+endTime); //The time being returned here is according to the region/locale/zone in which the application is hosted.
LocalTime current = LocalTime.now();
int hour = current.getHour(); // Getting the hours, minutes and seconds components
int minute = current.getMinute();
int second = current.getSecond();
System.out.println("Hour: "+hour+" Minute: "+minute+" Second: "+second); //The time being returned here is according to the region/locale/zone in which the application is hosted.
System.out.println();
System.out.println("*****LocalDateTime*****");
LocalDateTime dateTime = LocalDateTime.now();
System.out.println("Date and Time: "+dateTime); //The time being returned here is according to the region/locale/zone in which the application is hosted.
System.out.println(dateTime.minusDays(3)); // Subtracting 3 days and output time is in ETC
//Run the above program in your system in order to see the difference
}
}
Output:
*****LocalDate*****
Today's date(System date): 2023-12-22
Adding 3 days: 2023-12-25
Please take the assessment as soon as possible
*****LocalTime*****
Start Time: 15:11:31.321
End Time: 16:11:31.321
Hour: 15 Minute: 11 Second: 31
*****LocalDateTime*****
Date and Time: 2023-12-22T15:11:31.321
2023-12-19T15:11:31.321