java 生产时间+顺序序列号

private static int serialNum = 0;
private static int serialLength = 5;
private static int serialMax = 99999;

private String generateSerialNo() {
String currentDate = new SimpleDateFormat(“yyyyMMddHHmmss”).format(new Date());
if (serialNum == serialMax) { serialNum = 0;
}
String serialNumStr = serialNum + “”;
StringBuilder serialNoBuilder = new StringBuilder(); for (int i = 0; i < serialLength - serialNumStr.length(); i++) {
serialNoBuilder.append(“0”);
}
serialNoBuilder.append(serialNumStr); serialNum++;
String SerialNo = “ASJ” + currentDate + serialNoBuilder;
return SerialNo;
}

你可能感兴趣的:(java 生产时间+顺序序列号)