- 上班打开时间生成器
运行以后,输入1生成上午打卡时间(范围在8:15:00~8:30:59),输入2生成下午打卡时间(范围在18:30:00~18:40:59),输入0,再输入年份和月份,生成工作日期,即不包含周六和周末(不包含农历放假时间,因为有点复杂,没有加入此功能)。时间可以根据自己的需要修改。不是什么高级玩意儿,纯属娱乐。
package workdays;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class WorkDays {
private static List<Date> getDates(int year, int month) {
List<Date> dates = new ArrayList<Date>();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
cal.set(Calendar.DATE, 1);
while (cal.get(Calendar.YEAR) == year && cal.get(Calendar.MONTH) < month) {
int day = cal.get(Calendar.DAY_OF_WEEK);
if (!(day == Calendar.SUNDAY || day == Calendar.SATURDAY)) {
dates.add((Date) cal.getTime().clone());
}
cal.add(Calendar.DATE, 1);
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
for (Date date : dates) {
System.out.println(df.format(date));
}
return dates;
}
public static void morning() {
String time = "";
String hour = "8";
String minute = "";
String second = "";
int sec = 0;
for (int i = 0; i < 22; i++) {
minute = String.valueOf((int) Math.floor(Math.random() * 15 + 15));
sec = (int) (Math.random() * 60);
if (sec < 10) {
second = "0" + sec;
} else {
second = String.valueOf(sec);
}
time = hour + ":" + minute + ":" + second;
System.out.println(time);
}
}
public static void afternoon() {
String time = "";
String hour = "18";
String minute = "";
String second = "";
int sec = 0;
for (int i = 0; i < 22; i++) {
minute = String.valueOf((int) Math.floor(Math.random() * 10 + 30));
sec = (int) (Math.random() * 60);
if (sec < 10) {
second = "0" + sec;
} else {
second = String.valueOf(sec);
}
time = hour + ":" + minute + ":" + second;
System.out.println(time);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
String input = sc.next();
if ("0".equals(input)) {
int year = sc.nextInt();
int month = sc.nextInt();
getDates(year, month);
} else if ("1".equals(input)) {
morning();
} else if ("2".equals(input)) {
afternoon();
} else if ("over".equals(input)) {
break;
}
}
}
}