自定义前缀和时间戳生成单号

来源:互联网 发布:js 数组 lastindexof 编辑:程序博客网 时间:2024/04/30 00:55
public static String getOrderNo(final String prefix) {
DateFormat df = new SimpleDateFormat("yyMMddHHmm");
String MI = "";
String last = "";
Date date = null;
synchronized (df) {
date = new Date();
Calendar CD = Calendar.getInstance();
MI = CD.get(Calendar.MILLISECOND) + "";
if (MI.length() < 3) {
Random random = new Random();
MI = (random.nextInt(999 - 100 + 1) + 100) + "";
}
Random random = new Random();
last = (random.nextInt(999 - 100 + 1) + 100) + "";
}
return prefix + df.format(date) + MI + last;
}
0 0
原创粉丝点击