代码类如下:
package com.modules.common.util; import java.text.SimpleDateFormat; import java.util.Date; public class SerialNoGenUtil { /** * Return serial number length = {interfaceNo} + 14 + 6 * @return serial number string with length = {prefix}+20 */ public static String getSerialNo(String interfaceNo) { SimpleDateFormat formater = new SimpleDateFormat("yyyyMMddHHmmss"); String randStr = String.valueOf((int) (Math.random() * 899999.0D) + 100000); return interfaceNo + formater.format(new Date()) + randStr; } /** * Return serial number length = 12 (HHmmss + 6-RAND) * @return serial number string of length 12 */ public static String getSerialNymd() { SimpleDateFormat formater = new SimpleDateFormat("HHmmss"); String randStr = String.valueOf((int) (Math.random() * 899999.0D) + 100000); return formater.format(new Date()) + randStr; } /** * Return serial number length 30 (yyyyMMddHHmmss + 6-RAND + 10-UU) * @return serial number string of length 30 */ public static String getSerialUUIDYmd() { SimpleDateFormat formater = new SimpleDateFormat("yyyyMMddHHmmss"); String randStr = String.valueOf((int) (Math.random() * 899999.0D) + 100000); return formater.format(new Date()) + randStr + java.util.UUID.randomUUID().toString().replace("-", "").substring(0, 10); } }