-
Notifications
You must be signed in to change notification settings - Fork 27
/
ThreeTen.java
47 lines (36 loc) · 1.48 KB
/
ThreeTen.java
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
import static java.lang.System.out;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.temporal.ChronoUnit;
// kudos to https://github.com/bbejeck
public class ThreeTen {
private static LocalDate today = LocalDate.of(2014, 3, 27);
public static void main(String...args) {
out.println("today=" + today);
out.println("month=" + today.getMonth());
out.println("year=" + today.getYear());
LocalDate thirtyDaysFromNow = today.plusDays(30);
out.println(thirtyDaysFromNow);
out.println("today still=" + today);
LocalDate nextMonth = today.plusMonths(1);
out.println(nextMonth);
LocalDate nextWeek = today.plus(1, ChronoUnit.WEEKS);
out.println(nextWeek);
LocalDate easter = LocalDate.of(2014, 4, 20);
out.println("easter=" + easter);
/*
Period twoMonths = Period.ofMonths(2);
out.println("2months=" + twoMonths);
out.println("2months from now=" + today.plus(twoMonths));
//*/
/*
Period timeUntilEaster = today.until(easter);
out.println("timeUntilEaster=" + timeUntilEaster);
out.println("timeUntilEaster=" + timeUntilEaster.getDays() + " days");
out.println("today - timeUntilEaster = " + today.minus(timeUntilEaster));
LocalDateTime ldt = today.atTime(6,45,0);
out.println("time=" + ldt);
//*/
}
}