信用卡有效期格式转换为MMYY、YYMM
生活随笔
收集整理的這篇文章主要介紹了
信用卡有效期格式转换为MMYY、YYMM
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// 將信用卡有效期格式轉換為MMYYpublic String expiredTimeToMMYY(String expiredTime) {try {if(expiredTime.contains("/") || expiredTime.contains("-")) {expiredTime = expiredTime.replace("/", "");expiredTime = expiredTime.replace("-", "");}String before = expiredTime.substring(0, 2);String after = expiredTime.substring(2, 4);BigDecimal big = new BigDecimal(before);BigDecimal times = new BigDecimal("12");int compareTo = big.compareTo(times);// 如果前兩位大于12,,代表是年/月的格式if (compareTo == 1) {expiredTime = after + before;} else {expiredTime = before + after;}} catch (Exception e) {LOG.error("轉換有效期格式有誤=======" + e);e.printStackTrace();return expiredTime;}return expiredTime;}// 將信用卡有效期格式轉換為YYMMpublic String expiredTimeToYYMM(String expiredTime) {try {if(expiredTime.contains("/") || expiredTime.contains("-")) {expiredTime = expiredTime.replace("/", "");expiredTime = expiredTime.replace("-", "");}String before = expiredTime.substring(0, 2);String after = expiredTime.substring(2, 4);BigDecimal big = new BigDecimal(before);BigDecimal times = new BigDecimal("12");int compareTo = big.compareTo(times);// 如果前兩位大于12,,代表是年/月的格式if (compareTo == 1) {expiredTime = before + after;} else {expiredTime = after + before;}} catch (Exception e) {LOG.error("轉換有效期格式有誤=======" + e);e.printStackTrace();return expiredTime;}return expiredTime;}
?
結果:
總結
以上是生活随笔為你收集整理的信用卡有效期格式转换为MMYY、YYMM的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 她太冷了
- 下一篇: UIFontDownLoad ----动