mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
生成16位id
This commit is contained in:
@@ -59,6 +59,10 @@ public class IdUtils {
|
||||
// 2.中间四位整数,标识日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
|
||||
String dayTime = sdf.format(new Date());
|
||||
|
||||
// 2.生成四位随机整数
|
||||
int valueOf = (int)((Math.random()*9+1)*1000);
|
||||
|
||||
// 3.生成uuid的hashCode值
|
||||
int hashCode = UUID.randomUUID().toString().hashCode();
|
||||
// 4.可能为负数
|
||||
@@ -66,8 +70,8 @@ public class IdUtils {
|
||||
hashCode = -hashCode;
|
||||
}
|
||||
// 5.算法处理: 0-代表前面补充0; 10-代表长度为10; d-代表参数为正数型
|
||||
String value = machineId + dayTime + String.format("%010d", hashCode);
|
||||
System.out.println(value);
|
||||
String value = machineId + valueOf + String.format("%010d", hashCode);
|
||||
// System.out.println(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user