forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendarDemo.java
More file actions
95 lines (86 loc) · 2.9 KB
/
CalendarDemo.java
File metadata and controls
95 lines (86 loc) · 2.9 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package onlyfun.caterpillar;
import java.util.Calendar;
public class CalendarDemo {
public static void main(String[] args) {
Calendar rightNow = Calendar.getInstance();
System.out.println("現在時間是:");
System.out.println("西元:" +
rightNow.get(Calendar.YEAR));
System.out.println("月:" +
getChineseMonth(rightNow));
System.out.println("日:" +
rightNow.get(Calendar.DAY_OF_MONTH));
System.out.println("星期:" +
getChineseDayOfWeek(rightNow));
}
public static String getChineseMonth(Calendar rightNow) {
String chineseMonth = null;
switch(rightNow.get(Calendar.MONTH)) {
case Calendar.JANUARY:
chineseMonth = "一";
break;
case Calendar.FEBRUARY:
chineseMonth = "二";
break;
case Calendar.MARCH:
chineseMonth = "三";
break;
case Calendar.APRIL:
chineseMonth = "四";
break;
case Calendar.MAY:
chineseMonth = "五";
break;
case Calendar.JUNE:
chineseMonth = "六";
break;
case Calendar.JULY:
chineseMonth = "七";
break;
case Calendar.AUGUST:
chineseMonth = "八";
break;
case Calendar.SEPTEMBER:
chineseMonth = "九";
break;
case Calendar.OCTOBER:
chineseMonth = "十";
break;
case Calendar.NOVEMBER:
chineseMonth = "十一";
break;
case Calendar.DECEMBER:
chineseMonth = "十二";
break;
}
return chineseMonth;
}
public static String getChineseDayOfWeek(
Calendar rightNow) {
String chineseDayOfWeek = null;
switch(rightNow.get(Calendar.DAY_OF_WEEK)) {
case Calendar.SUNDAY:
chineseDayOfWeek = "日";
break;
case Calendar.MONDAY:
chineseDayOfWeek = "一";
break;
case Calendar.TUESDAY:
chineseDayOfWeek = "二";
break;
case Calendar.WEDNESDAY:
chineseDayOfWeek = "三";
break;
case Calendar.THURSDAY:
chineseDayOfWeek = "四";
break;
case Calendar.FRIDAY:
chineseDayOfWeek = "五";
break;
case Calendar.SATURDAY:
chineseDayOfWeek = "六";
break;
}
return chineseDayOfWeek;
}
}