java编写全年考勤日历

网友投稿 368 2023-01-18


java编写全年考勤日历

本文实例为大家分享了java编写全年考勤日历的具体代码,供大家参考,具体内容如下

JAVA代码:

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 map = getCalendarDetail();

// 每行开头灰色的格数

int headDisabledDays;

// html.append("

html.append("

html.append("

for (int col = 0; col < maxCols; col++) {

html.append("

html.append(weekdays[col % weekdays.length]);

htmlkMwTU.append("

}

html.append("

Calendar cal = Calendar.getInstance();

int month = cal.get(Calendar.MONTH);

for (int months = 0; months < 12; months++) {

html.append("

String s;

s = formatHeader.format(cal.getTime());

html.append("

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("

// 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(" title='" + formatTitle.format(cal.getTime())

+ "'");

html.append(">");

html.append(cal.get(Calendar.DAY_OF_MONTH));

html.append("

cal.add(Calendar.DAY_OF_MONTH, 1);

}

html.append("

if (month == cal.get(Calendar.MONTH)) {

cal.add(Calendar.MONTH, 1);

}

month = cal.get(Calendar.MONTH);

}

// html.append("

return html.toString();

}

public String getHtml() {

return html;

}

public void setHtml(String html) {

this.html = html;

}

private HashMap getCalendarDetail() {

HashMap map;

map = new HashMap();

map.put("20150404", "2");

map.put("20150405", "2");

map.put("20150406", "2");

map.put("20150501", "2");

map.put("20150502", "2");

map.put("20150503", "2");

map.put("20150622", "2");

map.put("20151001", "2");

map.put("20151002", "2");

map.put("20151003", "2");

return map;

}

public String dateCellClick(){

return SUCCESS;

}

}

action配置:

HTML代码:

<%@ page language="java" contentType="text/html; charshttp://et=utf-8"

pageEncoding="utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path;

%>

<%@taglib prefix="s" uri="/struts-tags"%>

href="<%=basePath%>/html/styles/styles.css" rel="external nofollow" />

效果如下


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:关于post测试文件下载的信息
下一篇:实现接口和使用接口吗(接口是怎么实现的)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~