「java排班时间」java做一个排班系统算法
本篇文章给大家谈谈java排班时间,以及java做一个排班系统算法对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、用java实现7个人值班,每人值班一周,从周一到周日,轮流值班
- 2、大神!java计算两个日期间隔天数程序出现问题,本月内没有问题,一旦跨月,既俩日期在不同月时结果有误!
- 3、你好,能不能教我用java编写一个待查询的排班表程序,就是可以用日期和班次查询的程序
- 4、java中的时间操作问题,难题求解
- 5、怎么用java 排班 轮排的
- 6、如何用EXCEL电子表格制作有特殊要求的排班表?
用java实现7个人值班,每人值班一周,从周一到周日,轮流值班
7个人值班,每人值班一周
从周一到周日,轮流值班
需求不清楚,到底是每人值一天,还是每人值一周?
如果是每人值一天,一周七天,七人轮流,那就不需要算法了.
大神!java计算两个日期间隔天数程序出现问题,本月内没有问题,一旦跨月,既俩日期在不同月时结果有误!
用java.text.SimpleDateFormat和java.util.Date来实现
Date d=new Date(); SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd"); System.out.println("今天的日期:"+df.format(d)); System.out.println("两天前的日期:" + df.format(new Date(d.getTime() - 2 * 24 * 60 * 60 * 1000))); //都是以毫秒计算 System.out.println("三天后的日期:" + df.format(new Date(d.getTime() + 3 * 24 * 60 * 60 * 1000)));
当然还可以用java.util.Calender来实现
你可以去看下api文档学习下
你好,能不能教我用java编写一个待查询的排班表程序,就是可以用日期和班次查询的程序
你这要用到数据库吧,能不能把的这个程序的所有需求说出来,比方说要界面吗,用什么数据库,具体实现什么功能等等!
java中的时间操作问题,难题求解
我以前遇到过类似的问题。就是做值班表 自动排班的时候。
我不知道用SQL语句怎么做;而且又不想插入空数据,于是就用程序实现的。
其中有部分实现了时间段的构造,你可以看下。应该不难解决。
//半自动排班
@SuppressWarnings("unchecked")
public ActionForward automatic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception{
ScheduletableActionForm newform = (ScheduletableActionForm)form;
String id_str = request.getParameter("id");
if(id_str==null){
id_str = newform.getSchedule().getId_string();
}
long id = Long.parseLong(id_str);
Schedule schedule = ScheduleDAO.getScheduleById(id);
//排班明细结束时间由排班表决定
Date enddate = schedule.getEnddate();
//排班模板时间段由该排班表已有的明细决定
List datelist = SchedulelineDAO.getSchedulelineShowSizeScheduleId(id);
if(datelist==null||datelist.size()==0){
newform.setErrormsg("请至少先选择一个排班循环");
}
else{//该datelist长度一定大于0,否则不允许进入自动排班
Date startpoint = (Date)datelist.get(0);
Date endpoint = (Date)datelist.get(datelist.size()-1);
//只排endpoint至enddate之间的明细
Date start_go = TimeFormat.getDateAfter(endpoint, 0, 0, 1, 0, 0, 0);
Date end_go = enddate;
//构造自动排班的日期列表
ArrayListDate datelist_go = new ArrayListDate();
Date tempdate = start_go;
while(!tempdate.after(end_go)){
datelist_go.add(tempdate);
tempdate = TimeFormat.getDateAfter(tempdate, 0, 0, 1, 0, 0, 0);
}
int size = datelist_go.size();
//构造模板日期列表
ArrayListDate modellist = new ArrayListDate();
Date tempmodel = startpoint;
while(!tempmodel.after(endpoint)){
modellist.add(tempmodel);
tempmodel = TimeFormat.getDateAfter(tempmodel, 0, 0, 1, 0, 0, 0);
}
int modelsize = modellist.size();
//班次列表
List shiftlist = ShiftDAO.getShiftlistByDeptid(schedule.getDeptid());
//按照自动排班的日期列表逐日进行
for(int i=0;isize;i++){
int modelNo = getModelNo(i,modelsize);
String modeldate_s = TimeFormat.dateToString("yyyy-MM-dd",(Date)modellist.get(modelNo));
Date linedate = datelist_go.get(i);
for(int j=0;jshiftlist.size();j++){//再按照班次进行
Scheduleline line = new Scheduleline();
Shift shift = (Shift)shiftlist.get(j);
long shiftid = shift.getId();
Scheduleline modelline = SchedulelineDAO.getSchedulelineTrTd(id, shiftid, modeldate_s);
if(modelline!=null){//如果不为空,复制过来进行插入
line.setId(IdCreater.getId("Scheduleline")); //id不复制
line.setDatea(linedate);
line.setMembers(modelline.getMembers());
line.setLeader(modelline.getLeader());
//line.setEndtime(modelline.getEndtime());
//line.setStarttime(modelline.getStarttime());
String datea_string = TimeFormat.dateToString("yyyy-MM-dd", linedate);
String starttime_str = datea_string+" "+TimeFormat.dateToString("HH:mm", shift.getStarttime());
Date nowdaytime = TimeFormat.stringToDate("yyyy-MM-dd", datea_string);
String endStr = shift.getEndstr();
if(endStr.equals("次日")){
nowdaytime = TimeFormat.getDateAfter(nowdaytime, 0, 0, 1, 0, 0, 0);
}
String endtime_str = TimeFormat.dateToString("yyyy-MM-dd", nowdaytime)+" "+TimeFormat.dateToString("HH:mm", shift.getEndtime());
line.setStarttime(TimeFormat.stringToDate("yyyy-MM-dd HH:mm", starttime_str));
line.setEndtime(TimeFormat.stringToDate("yyyy-MM-dd HH:mm", endtime_str));
line.setShiftname(modelline.getShiftname());
line.setScheduleid(modelline.getScheduleid());
line.setShiftid(modelline.getShiftid());
SchedulelineDAO.addScheduleline(line);
}
}
}
newform.setErrormsg("排班成功!");
}
newform.getSchedule().setId_string(id_str);
ActionForward forward = detail(mapping, newform, request, response);
return forward;
}
//计算第i行的排班表应该选择的模板的行号j
private static int getModelNo(int i,int modelsize){
return i%modelsize;
}
//****************************自动排班结束**************************//
补充一下:中间有个TimeFormat方法,贴出来
public class TimeFormat {
//将传入的时间按照指定的格式转化成字符串返回
//注意传入的format_type必须为指定的时间格式,比如"yyyy-MM-dd HH:mm:ss"
//传入的date必须为Date型
public static String dateToString(String format_type,Date time_Date){
if(time_Date==null)return "";
SimpleDateFormat sdf = new SimpleDateFormat(format_type);
String format_time = sdf.format(time_Date);
return format_time;
}
//将传入的字符串转化成指定格式的日期返回
//注意传入的format_type必须为指定的时间格式,比如"yyyy-MM-dd HH:mm:ss"
//传入的time_str必须为符合format_type格式的字符串
public static Date stringToDate(String format_type,String time_Str){
SimpleDateFormat sdf = new SimpleDateFormat(format_type);
if(time_Str.length()format_type.length()){
if(time_Str.length()==4){
time_Str += "-00-00 00:00:00";
}
if(time_Str.length()==7){
time_Str += "-00 00:00:00";
}
if(time_Str.length()==10){
time_Str += " 00:00:00";
}
if(time_Str.length()==13){
time_Str += ":00:00";
}
if(time_Str.length()==16){
time_Str += ":00";
}
}
Date date = new Date();
try{
date = sdf.parse(time_Str);
}catch(Exception e){
e.printStackTrace();
}
return date;
}
//将传入的Date型数据转化成指定格式的Date型返回
//注意传入的format_type必须为指定的时间格式,比如"yyyy-MM-dd HH:mm:ss"
//传入的time_Date必须为Date型时间
public static Date dateToDate(String format_type,Date time_Date){
String format_str = dateToString(format_type,time_Date);
Date format_date = stringToDate(format_type,format_str);
return format_date;
}
public static String getCurrentDate(String format_type){
SimpleDateFormat sdf = new SimpleDateFormat(format_type);
String format_time = sdf.format(new Date());
return format_time;
}
//根据传入的日期取得星期,返回星期的字符串,形如"星期二"
public static String getWeekTimeByDate(Date date){
String week = "";
String[] dayNames = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五","星期六"};
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)-1;
if(dayOfWeek0){
dayOfWeek=0;
}
week = dayNames[dayOfWeek];
return week;
}
//取得传入日期a年,b月,c天,d小时,e分钟,f秒以后的日期,若想得到以前的,参数为负值即可
public static Date getDateAfter(Date date,int years,int months,int days,int hours,int minutes,int seconds){
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.YEAR, years);
cal.add(Calendar.MONTH, months);
cal.add(Calendar.DATE, days);
cal.add(Calendar.HOUR, hours);
cal.add(Calendar.MINUTE, minutes);
cal.add(Calendar.SECOND, seconds);
date = cal.getTime();
return date;
}
//传入一个date得到该date的月
public static int getMonth(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
return c.get(Calendar.MONTH)+1;
}
//传入一个date得到该date的月
public static int getDay(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
return c.get(Calendar.DAY_OF_MONTH);
}
// 传入一个date得到该date的月
public static int getYear(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
return c.get(Calendar.YEAR);
}
//取得A时间减去B时间后的毫秒数
public static long getPoorSeconds(Date a,Date b){
Calendar timea = Calendar.getInstance();
Calendar timeb = Calendar.getInstance();
timea.setTime(a);
timeb.setTime(b);
return timea.getTimeInMillis() - timeb.getTimeInMillis();
}
public static void main(String[] args) {
}
}
怎么用java 排班 轮排的
应该用不上什么线程,一次性把所有的班都排好
六个元素的数组
两个指针,一个是工作日当值人,一个是周末当值人,初始都是0
从今天开始到指定某一天,譬如年底
int idx_workday =0;
int idx_weekend =0;
ArrayList assignment = new ArrayList();
day = today;
while(day不是年底){
int i;
if (day is workday){
i = idx_workday++;
assignment.add(i);
if (idx_workday 5) idx_workday = 0;
}else{
i = idx_weekend++;
assignment.add(i);
if (idx_weekend 5) idx_weekend= 0;
}
}
output assignment
如何用EXCEL电子表格制作有特殊要求的排班表?
也不用什么函数吧。就做一个两周的模版执行。
不过,休息日前后的白班夜班应该是交替的。不可能按你最后的要求。除非上夜班的永远上夜班,白班的永远是白班
第三条规定好像行不通,除非有一天连续24小时上班。只能是每周理由休息日后白班和黑板轮换。
关于java排班时间和java做一个排班系统算法的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-29,除非注明,否则均为
原创文章,转载请注明出处。