新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
使用java怎么實(shí)現(xiàn)一個(gè)全年考勤日歷
本篇文章為大家展示了使用java怎么實(shí)現(xiàn)一個(gè)全年考勤日歷,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)是少有的成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、營(yíng)銷型企業(yè)網(wǎng)站、微信小程序、手機(jī)APP,開發(fā)、制作、設(shè)計(jì)、外鏈、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,2013年開創(chuàng)至今,堅(jiān)持透明化,價(jià)格低,無套路經(jīng)營(yíng)理念。讓網(wǎng)頁驚喜每一位訪客多年來深受用戶好評(píng)
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() { // 每行開頭灰色的格數(shù) int headDisabledDays; // 當(dāng)月的天數(shù) 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日"); HashMapmap = getCalendarDetail(); // 每行開頭灰色的格數(shù) int headDisabledDays; // html.append(" \r\n"); html.append("
\r\n"); return html.toString(); } public String getHtml() { return html; } public void setHtml(String html) { this.html = html; } private HashMap\r\n"); html.append(" \r\n"); Calendar cal = Calendar.getInstance(); int month = cal.get(Calendar.MONTH); for (int months = 0; months < 12; months++) { html.append("\r\n"); for (int col = 0; col < maxCols; col++) { html.append(" "); html.append(weekdays[col % weekdays.length]); html.append(" \r\n"); } html.append("\r\n"); String s; s = formatHeader.format(cal.getTime()); html.append(" \r\n"); if (month == cal.get(Calendar.MONTH)) { cal.add(Calendar.MONTH, 1); } month = cal.get(Calendar.MONTH); } // html.append("" + s + " \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("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(" \r\n"); cal.add(Calendar.DAY_OF_MONTH, 1); } html.append("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; charset=utf-8" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path; %> <%@taglib prefix="s" uri="/struts-tags"%>Login page /html/styles/styles.css" rel="external nofollow" />
效果如下
上述內(nèi)容就是使用java怎么實(shí)現(xiàn)一個(gè)全年考勤日歷,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享文章:使用java怎么實(shí)現(xiàn)一個(gè)全年考勤日歷
標(biāo)題鏈接:http://fisionsoft.com.cn/article/ighigo.html