本文实例为大家分享了java编写全年考勤日历的具体代码,供大家参考,具体内容如下
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
package com.wp.action;
import java.text.simpledateformat;
import java.util.arraylist;
import java.util.calendar;
import java.util.hashmap;
public class calendaraction extends mainaction {
private static final long serialversionuid = 1l;
private int maxcols;
private string html;
private string clickdate;
public string getclickdate() {
return clickdate;
}
public void setclickdate(string clickdate) {
this .clickdate = clickdate;
}
public string init() {
calendar cal = calendar.getinstance();
int month = cal.get(calendar.month) + 1 ;
initmaxcols();
html = createtbl();
return success;
}
private void initmaxcols() {
// 每行开头灰色的格数
int headdisableddays;
// 当月的天数
int onemonthdays;
calendar cal = calendar.getinstance();
cal.set(calendar.day_of_month, 1 );
for ( int i = 0 ; i < 12 ; i++) {
if (cal.get(calendar.day_of_week) == calendar.sunday) {
// 周日空六格
headdisableddays = 6 ;
} else {
headdisableddays = cal.get(calendar.day_of_week)
- calendar.monday;
}
onemonthdays = cal.getactualmaximum(calendar.day_of_month);
if (headdisableddays + onemonthdays > maxcols) {
maxcols = headdisableddays + onemonthdays;
}
cal.add(calendar.month, 1 );
}
}
private string createtbl() {
stringbuffer html = new stringbuffer();
string[] weekdays = { "一" , "二" , "三" , "四" , "五" , "六" , "日" };
simpledateformat formattd = new simpledateformat( "yyyymmdd" );
simpledateformat formatheader = new simpledateformat( "yyyy年mm月" );
simpledateformat formattitle = new simpledateformat( "yyyy年mm月dd日" );
hashmap<string, string> map = getcalendardetail();
// 每行开头灰色的格数
int headdisableddays;
// html.append("<table id='caltbl'>\r\n");
html.append( "<tr>\r\n" );
html.append( "<th></th>\r\n" );
for ( int col = 0 ; col < maxcols; col++) {
html.append( "<th>" );
html.append(weekdays[col % weekdays.length]);
html.append( "</th>\r\n" );
}
html.append( "</tr>\r\n" );
calendar cal = calendar.getinstance();
int month = cal.get(calendar.month);
for ( int months = 0 ; months < 12 ; months++) {
html.append( "<tr>\r\n" );
string s;
s = formatheader.format(cal.gettime());
html.append( "<td class='rowheader'>" + s + "</td>\r\n" );
cal.set(calendar.day_of_month, 1 );
if (cal.get(calendar.day_of_week) == calendar.sunday) {
// 周日空六格
headdisableddays = 6 ;
} else {
headdisableddays = cal.get(calendar.day_of_week)
- calendar.monday;
}
cal.add(calendar.day_of_month, -headdisableddays);
for ( int col = 0 ; col < maxcols; col++) {
html.append( "<td id='" );
string date = formattd.format(cal.gettime());
html.append(date + "' " );
// if (headdisableddays-- > 0) {
// html.append("class='disabledtd'");
// }else
if (month != cal.get(calendar.month)) {
html.append( "class='disabledtd'" );
} else if (map.containskey(formattd.format(cal.gettime()))) {
int type = integer.parseint(map.get(formattd.format(cal
.gettime())));
if (type == 1 ){
//html.append("class='holidaytd'");
} else if (type == 2 ){
html.append( "class='holidaytd'" );
}
} else if (cal.get(calendar.day_of_week) == calendar.saturday
|| cal.get(calendar.day_of_week) == calendar.sunday) {
html.append( "class='weekendtd'" );
} else {
html.append( "class='generaltd'" );
}
html.append( " java" id="highlighter_932381">
html代码:
效果如下
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。 原文链接:https://blog.csdn.net/u013816347/article/details/44259455 延伸 · 阅读
精彩推荐
|