手机号 、身份证号脱敏处理、求年龄等

        //        str:被替换的字符串
        //        overlay:替换后的内容
        //        int :替换的起始下标(0开始计数,包含)
        //        end:替换的结尾下标(不包含)
        String phone="18835698188";
        String overlay = StringUtils.overlay(phone, "****", 3, 7);
        System.out.println(overlay);

        String idCard="410527202103031316";
        String idCard2 = StringUtils.overlay(idCard, "****", 6, 14);
        System.out.println(idCard2);
  /**
     * 从身份证中获取出生日期
     */
    public static String getBirthDayFromIDCard(String idno) {
        Calendar cd = Calendar.getInstance();
        if (idno.length() == 15) {
            cd.set(Calendar.YEAR, Integer.valueOf("19" + idno.substring(6, 8))
                    .intValue());
            cd.set(Calendar.MONTH, Integer.valueOf(idno.substring(8, 10))
                    .intValue() - 1);
            cd.set(Calendar.DAY_OF_MONTH,
                    Integer.valueOf(idno.substring(10, 12)).intValue());
        } else if (idno.length() == 18) {
            cd.set(Calendar.YEAR, Integer.valueOf(idno.substring(6, 10))
                    .intValue());
            cd.set(Calendar.MONTH, Integer.valueOf(idno.substring(10, 12))
                    .intValue() - 1);
            cd.set(Calendar.DAY_OF_MONTH,
                    Integer.valueOf(idno.substring(12, 14)).intValue());
        }
        return DateUtils.dateToString(cd.getTime());
    }
  /**
     * 计算年龄
     *
     * @param birthday 生日日期
     * @param calcDate 要计算的日期点
     * @return
     */
    public static int calcAge(Date birthday, Date calcDate) {

        int cYear = DateUtils.getYearOfDate(calcDate);
        int cMonth = DateUtils.getMonthOfDate(calcDate);
        int cDay = DateUtils.getDayOfDate(calcDate);
        int bYear = DateUtils.getYearOfDate(birthday);
        int bMonth = DateUtils.getMonthOfDate(birthday);
        int bDay = DateUtils.getDayOfDate(birthday);

        if (cMonth > bMonth || (cMonth == bMonth && cDay > bDay)) {
            return cYear - bYear;
        } else {
            return cYear - 1 - bYear;
        }
    }

    /**
     * 从身份证中获取出生日期
     */
    public static String getBirthDayFromIDCard(String idno) {
        Calendar cd = Calendar.getInstance();
        if (idno.length() == 15) {
            cd.set(Calendar.YEAR, Integer.valueOf("19" + idno.substring(6, 8))
                    .intValue());
            cd.set(Calendar.MONTH, Integer.valueOf(idno.substring(8, 10))
                    .intValue() - 1);
            cd.set(Calendar.DAY_OF_MONTH,
                    Integer.valueOf(idno.substring(10, 12)).intValue());
        } else if (idno.length() == 18) {
            cd.set(Calendar.YEAR, Integer.valueOf(idno.substring(6, 10))
                    .intValue());
            cd.set(Calendar.MONTH, Integer.valueOf(idno.substring(10, 12))
                    .intValue() - 1);
            cd.set(Calendar.DAY_OF_MONTH,
                    Integer.valueOf(idno.substring(12, 14)).intValue());
        }
        return DateUtils.dateToString(cd.getTime());
    }

data = [ {"手机号": "18845298308","身份证号": "110101199001011234", "年龄": 31, "出生日期": "1990-01-01"}, {"手机号": "13836277378", "身份证号": "110101199002022345", "年龄": 30, "出生日期": "1990-02-02"}, {"手机号": "13284521826", "身份证号": "110101198903033456", "年龄": 32, "出生日期": "1989-03-03"}, {"手机号": "15164614435", "身份证号": "110101198904044567", "年龄": 31, "出生日期": "1989-04-04"}, {"手机号": "19155675434", "身份证号": "110101198905055678", "年龄": 30, "出生日期": "1989-05-05"}, {"手机号": "13908764535", "身份证号": "110101199006066789", "年龄": 31, "出生日期": "1990-06-06"}, {"手机号": "13222222222", "身份证号": "110101199007077890", "年龄": 30, "出生日期": "1990-07-07"}, {"手机号": "13333333333", "身份证号": "110101199008088901", "年龄": 31, "出生日期": "1990-08-08"}, {"手机号": "13444444444", "身份证号": "110101199009099012", "年龄": 30, "出生日期": "1990-09-09"}, {"手机号": "13000000000", "身份证号": "110101199010101123", "年龄": 31, "出生日期": "1990-10-10"} ]# 置乱脱敏函数 def shuffle_mask(): random.shuffle(data) show_data() def zhiluan(): def permutation(text): # 将字符串转换为列表并打乱顺序 text_list = list(text) random.shuffle(text_list) # 将打乱后的列表转换为字符串 result = ''.join(text_list) return resultshuffle_mask_btn = Button(root, text="置乱脱敏", command=shuffle_mask) shuffle_mask_btn.grid(row=1, column=2)怎么将代码合并使得点击置乱脱敏按钮能实现data中手机号身份证号脱敏
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值