Skip to content

Commit eb2d38a

Browse files
authored
Create JavaDateTimeArithmetic.java
1 parent c78b310 commit eb2d38a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.zetcode;
2+
3+
import java.time.LocalDate;
4+
import static java.time.temporal.ChronoUnit.DAYS;
5+
6+
public class JavaDateTimeArithmetic {
7+
8+
public static void main(String[] args) {
9+
10+
LocalDate now = LocalDate.now();
11+
LocalDate ndate1 = now.plusDays(30);
12+
13+
System.out.println(ndate1);
14+
15+
LocalDate ndate2 = now.minusWeeks(15);
16+
System.out.println(ndate2);
17+
18+
19+
LocalDate newYear = LocalDate.of(2018, 1, 1);
20+
long dif = DAYS.between(newYear, now);
21+
System.out.printf("Days passed since beginning of 2018: %d%n", dif);
22+
}
23+
}

0 commit comments

Comments
 (0)