package util;
import org.apache.http.client.utils.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.logging.SimpleFormatter;
/**
* @author 子夕
* @version 1.0
* @description: 生成流水号
* @date 2021/12/21 14:49
*/
public class OrderUtil {
public static void main(String[] args) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
System.out.println(generateOrderSN());
}
long end = System.currentTimeMillis();
}
private static final SimpleDateFormat sf= new SimpleDateFormat("yyyyMMddHHmmss");
public static String generateOrderSN() {
StringBuffer orderSNBuffer = new StringBuffer();
orderSNBuffer.append(sf.format(new Date()));
orderSNBuffer.append(getRandomString(7));
return orderSNBuffer.toString();
}
private static int getRandomString(int num){
double random = Math.random();
return (int) (random*Math.pow(10,num));
}
}
java常用工具类整理-流水号
最新推荐文章于 2024-07-17 08:32:16 发布