Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (45 loc) · 1.54 KB

File metadata and controls

58 lines (45 loc) · 1.54 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package chapter13;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import static java.lang.System.out;
import static java.time.temporal.ChronoUnit.DAYS;
/**
* 使用新Api打印日历
*/
public class NewTimeDemo {
public static void main(String[] args) {
LocalDate nowDate = LocalDate.now();
Map<Integer, String> weekStr = new HashMap<>();
weekStr.put(0, "日");
weekStr.put(1, "一");
weekStr.put(2, "二");
weekStr.put(3, "三");
weekStr.put(4, "四");
weekStr.put(5, "五");
weekStr.put(6, "六");
System.out.printf("%d-%d-%d 星期%s\n",
nowDate.getYear(),
nowDate.getMonth().getValue(),
nowDate.getDayOfMonth(),
weekStr.get(nowDate.getDayOfWeek().getValue()));
weekStr.values().forEach((val) -> out.print(val + "\t"));
out.println();
LocalDate firstDate = nowDate.minus(nowDate.getDayOfMonth()-1, DAYS);
int lastDate = nowDate.lengthOfMonth();
int firstDayInMonth = firstDate.getDayOfMonth();
LocalDate curDate = firstDate;
for (int i = 1; i <= lastDate; i++) {
curDate = curDate.plus(1, DAYS);
if (i == 1) {
for (int j = 0; j < firstDayInMonth; j++) {
System.out.print("\t");
}
}
out.print(i + "\t");
if (curDate.getDayOfWeek().getValue() == 7) {
out.println();
}
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.