如何生成16位流水号
/** * @Description: 获取long类型16流水号 * @return serialNo long类型16流水号 * @date 2017年07月20日 下午03:55:21 */ public static long getTimeSerialNo(){ long serialNo; Random r = new Random(); Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR)-2000; int month = c.get(Calendar.MONTH) + 1; int day = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); int ms = c.get(Calendar.MILLISECOND); serialNo = (long)(year * 10000 + month * 100 + day); serialNo = serialNo * 1000000 + hour * 10000 + minute * 100 + second; serialNo = ( serialNo * 1000 + ms ) * 1000 + r.nextInt(1000); return serialNo; } /** * @Description: 获取String类型16流水号 * @return String类型16流水号 * @date 2017年07月20日 下午03:55:21 */ public static String getTimeSerialNoStr(){ StringBuilder serialNo=new StringBuilder(); Random r = new Random(); Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR)-2000; int month = c.get(Calendar.MONTH) + 1; int day = c.get(Calendar.DAY_OF_MONTH); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int second = c.get(Calendar.SECOND); int ms = c.get(Calendar.MILLISECOND); serialNo.append(year).append(month).append(day) .append(hour).append(minute).append(second) .append(ms).append(r.nextInt(1000)); return serialNo.toString(); }