Demo

  • 上班打开时间生成器
    运行以后,输入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());
            }
            // 相当于i++
            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;
            }
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值