package com.hytc.util.java;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Copyright © 2018****. All rights reserved.
*
* @Prject
* @Title CardCreateUtils.java
* @date 2018年4月9日 下午1:58:24
* @author PengYan
* @version: v1.0
*/
public class CardCreateUtils {
/**
* 去除卡号前的0
*
* @param num
* 卡号
* @return
*/
public static int getNum(String num) {
int result = 0;
for (int index = 0; index < num.length(); index++) {
if (index != num.length()) {
String str = num.substring(index, index + 1);
if (!str.equals("0")) {
result = Integer.valueOf(num.substring(index - 1));
break;
}
}
}
return result;
}
/**
* 在卡号前加上0
*
* @param length
* 卡号长度
* @param card
* 卡号
* @return
*/
public static String setNum(int length, String card) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length - card.length(); i++) {
builder.append("0");
}
builder.append(card);
return builder.toString();
}
/**
* <p>获取卡号段</p>
*
* @param startNum 开始卡号
* @param endNum 结束卡号
* @return 卡号段
*/
public static List<String> getNumList(String startNum, String endNum) {
List<String> numberList = new ArrayList<String>();
Integer start = getNum(startNum);
Integer end = getNum(endNum);
for (; start < end + 1; start++) {
numberList.add(setNum(7, String.valueOf(start)));
}
return numberList;
}
/**
* 获取当前时间
*
* @return
*/
public static String getNowTime() {
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
return sdFormat.format(new Date());
}
public static void main(String[] args) {
System.out.println(getNum("0000001"));
System.out.println(setNum(7, "1"));
System.out.println(getNumList("0000011", "0000020"));
System.out.println(getNowTime());
}
}
卡号截取和补充
最新推荐文章于 2024-05-24 08:58:49 发布