com.gitee.cliveyuan.tools.IdTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-tools Show documentation
Show all versions of java-tools Show documentation
Some commonly used methods in java
package com.gitee.cliveyuan.tools;
import com.gitee.cliveyuan.tools.enums.DateTimeFormat;
import java.util.UUID;
/**
* ID生成工具
*
* @author clive
* Created on 2018/07/27
* @since 1.0
*/
public class IdTools {
private IdTools(){}
/**
* 随机一个原生UUID
*
*/
public static String randomUUID() {
return UUID.randomUUID().toString();
}
/**
* 随机去掉横杠的UUID
*
*/
public static String randomShortUUID() {
String uuid = randomUUID();
// 去掉“-”符号
return uuid.replaceAll("-", "");
}
/**
* 生成以日期时间开头的20位订单号
*
*/
public static String genOrderNo() {
String dateTime = DateTimeTools.format(DateTimeTools.now(), DateTimeFormat.DATE_TIME_0);
int randomInt = MathTools.randomInt(100000, 999999);
return dateTime + randomInt;
}
}