-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalDateExamples.java
More file actions
37 lines (33 loc) · 1.12 KB
/
LocalDateExamples.java
File metadata and controls
37 lines (33 loc) · 1.12 KB
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
import java.time.*;
public class LocalDateExamples {
public static void main(String[] args) {
System.out.println("LocalDate example");
localDateExample();
System.out.println("Leap Year Example");
isLeapYear();
System.out.println("Add Date And Time Example");
addDateAndTime();
}
// LocalDate Example
public static void localDateExample() {
LocalDate date = LocalDate.now();
LocalDate yesterday = date.minusDays(1);
LocalDate tomorrow = yesterday.plusDays(2);
System.out.println("Today date: " + date);
System.out.println("Yesterday date: " + yesterday);
System.out.println("Tommorow date: " + tomorrow);
}
// Leap Year Example
public static void isLeapYear() {
LocalDate date1 = LocalDate.of(2017, 1, 13);
System.out.println(date1 + " is a leap year? " + date1.isLeapYear());
LocalDate date2 = LocalDate.of(2016, 9, 23);
System.out.println(date2 + " is a leap year? " + date2.isLeapYear());
}
//Add Date With Time
public static void addDateAndTime(){
LocalDate date = LocalDate.of(2017, 1, 13);
LocalDateTime datetime = date.atTime(1,50,9);
System.out.println(datetime);
}
}