package com.zwj.tools;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Get_timeCardState {
/**
* 模块功能:考勤, 记录迟到、早退时间
*/
public static void main(String[] args) {
String s = getState();
System.out.println(s);
}
public static String getState() {
String state = "正常";
DateFormat df = new SimpleDateFormat("HH:mm:ss");
Date d = new Date();
try {
Date d1 = df.parse("08:00:00");
Date d2 = df.parse(df.format(d));
Date d3 = df.parse("18:00:00");
int t1 = (int) d1.getTime();
int t2 = (int) d2.getTime();
int t3 = (int) d3.getTime();
if (t2 < t1) {
long between = (t1 - t2) / 1000;// 除以1000是为了转换成秒
long hour1 = between % (24 * 3600) / 3600;
long minute1 = between % 3600 / 60;
state = "迟到 :" + hour1 + "时" + minute1 + "分";
} else if (t2 < t3) {
long between = (t3 - t2) / 1000;// 除以1000是为了转换成秒
long hour1 = between % (24 * 3600) / 3600;
long minute1 = between % 3600 / 60;
state = "早退 :" + hour1 + "时" + minute1 + "分";
}
return state;
} catch (Exception e) {
return state;
}
}
}
模块功能:考勤, 记录迟到、早退时间
最新推荐文章于 2022-10-09 10:08:24 发布