日历签到 java_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("
\r\n");
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");
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH);
for (int months = 0; months < 12; months++) {
html.append("
\r\n");
String s;
s = formatHeader.format(cal.getTime());
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("
// 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("
\r\n");
cal.add(Calendar.DAY_OF_MONTH, 1);
}
html.append("
\r\n");
if (month == cal.get(Calendar.MONTH)) {
cal.add(Calendar.MONTH, 1);
}
month = cal.get(Calendar.MONTH);
}
// html.append("
\r\n");
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代码:
pageEncoding="utf-8"%>
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path;
%>
.disabledTd{
background-color:gray;
}
.weekendTd{
background-color:yellow;
}
.holidayTd{
background-color:green;
}
.generalTd{
background-color:white;
}
#calTbl{
font-family: verdana,arial,sans-serif;
font-size:13px;
color:#333333;
border-width: 1px;
border-color: #a9c6c9;
border-collapse: collapse;
}
#calTbl th{
border-width: 1px;
padding: 4px;
border-style: solid;
border-color: #a9c6c9;
background-color:olive;
}
#calTbl td {
border-width: 1px;
padding: 4px;
border-style: solid;
border-color: #a9c6c9;
}
.rowHeader{
background-color:olive;
}
Login page
href="/html/styles/styles.css" rel="external nofollow" />
$(document).ready(function(){
var checkType = 0;
$.post('calendar',{},function(data,status)
{
if(data != null && data.html != null && data.html != ""){
$("#calTbl").html( data.html);
$("#calTbl td").click(tdClick);
$("#checkType input").click(typeCheck);
}
}).error(function(){
});
var tdClick = function(){
if(this.className == 'rowHeader' || this.className == 'disabledTd'){
return;
}
if(checkType != null && checkType != "" && checkType != 0){
if(checkType == 1){
this.style.backgroundColor="white";
}else if(checkType == 2){
this.style.backgroundColor="yellow";
}else if(checkType == 3){
this.style.backgroundColor="green";
}
}
};
var typeCheck = function(){
checkType = this.value;
};
});
效果如下
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
日历签到 java_java编写全年考勤日历相关推荐
- android仿钉钉日程日历,Flutter仿钉钉考勤日历的示例代码
本文主要介绍了Flutter仿钉钉考勤日历的示例代码,分享给大家,具体如下: 效果 原型 开发 1. 使用 // 考勤日历 DatePickerDialog( initialDate: DateTim ...
- android 钉钉考勤日历,Flutter仿钉钉考勤日历
作用 原型 开发 运用 // 考勤日历 DatePickerDialog( initialDate: DateTime.now(), firstDate: DateTime(2020), lastDa ...
- 日历签到 mysql_php+mysql+jquery实现日历签到功能的方法
本文主要介绍了php+mysql+jquery实现日历签到功能的过程与步骤,具有很好的参考价值 在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到 ...
- js php 实现日历签到_php+mysql+jquery实现日历签到功能
在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤. 1.日历签到样式: 2.本次签到只记录本月 ...
- js php 实现日历签到_基于jquery实现日历签到功能_jquery
在一些任务游戏.贴吧管理中都会有一个签到功能,帮助大家记录登录天数,积累等级经验,这个日历签到功能是如何实现的,本文为大家进行演. 本文实例讲述了基于jquery实现日历签到功能.分享给大家供大家参考 ...
- js php 实现日历签到_php+mysql+jquery实现日历签到功能的过程与步骤
在网站开发过程中我们会经常用到签到功能来奖励用户积分,或者做一些其他活动.这次项目开发过程中做了日历签到,因为没有经验所有走了很多弯路,再次记录过程和步骤.日历签到样式: 本次签到只记录本月签到数,想 ...
- 日历签到 java_Java实现按年月打印日历功能【基于Calendar】
本文实例讲述了Java实现按年月打印日历功能.分享给大家供大家参考,具体如下: import java.text.ParseException; import java.text.SimpleDate ...
- java日历考勤_JAVA做全年考勤日历
JAVA代码: package com.wp.action; import java.text.SimpleDateFormat; import java.util.ArrayList; import ...
- java实现日历签到功能_[java] 可视化日历的实现(基于Calendar类 )
写在前面 博文安排顺序如下 1.写在前面 2.源码 3.思路 4.相关知识 该小程序是对Date类及其相关类的复习 要求如下图:实现可视化日历 实现思路 1.先从键盘输入指定格式的字符串(str) 2 ...
最新文章
- CocoaPods原理(一)
- 陶哲轩实分析定理17.3.8(三)
- 返回一个循环整数组最大子数组和
- 几个有用的word小技巧,保准提升效率~
- 第41课 蜗牛与葡萄树 《小学生C++趣味编程》
- 栈2——局部变量要初始化的原因
- 数据库-MySQL-结果集-ASORDER BY
- 多线程、方便扩展的Windows服务程序
- iview兼容ie8_iview在ie9及以上的兼容问题解决方案__Vue.js__JavaScript__前端__iView
- Android零基础入门第68节:完善RecyclerView,添加首尾视图
- Apache下的FileUtils.listFiles方法简单使用技巧
- Atitit 程序设计概论 艾提拉著作 目录 1. 界面ui设计	1 2. 编程语言部分	1 3. 面向对象的程序设计	1 4. 算法章节 数据结构	1 5. 第21章 标准库	2 5.1. 文件i
- 硬盘保护卡(增霸卡)的工作原理
- 由于应用universal link 校验不通过 ios应用升级SDK 更换Universal Links校验
- 捋一捋Vue构造函数
- 滚动抽奖html怎么做的,抽奖.html
- shape_predictor_68_face_landmarks.dat 下载地址
- 有一个人愿意参加第一届校园活力健美操这
- 【统计机器学习-李航】第5章 决策树
- 六款窗口比较器电路设计原理