package com.framework.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author zkx
* @create 2020-05-21 下午 1:40
*/
public class OrderCodeUtils {
/**
* 生成编号(当前日期后六位+4位随机数组成)
*
* @return
* @throws Exception
*/
public static String createOrderCode(Date date) {
//生成格式化日期为"yymmdd"
DateFormat format = new SimpleDateFormat("yyMMdd");
if(null == date){
date = new Date();
}
StringBuffer buffer = new StringBuffer();
buffer.append(format.format(date));
String code = buffer.toString();
//随机生成四位数
String timeMillis = System.currentTimeMillis() + "";
String randomNum = timeMillis.substring(timeMillis.length() - 4);
//生成订单编号
String orderCode = code + randomNum;
return orderCode;
}
/**
* 随机生成年月日时分秒+随机3位数的退款单号
* @return
*/
public static String getRandomFileName() {
SimpleDateFormat simpleDateFormat;
simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
Date date = new Date();
String str = simpleDateFormat.format(date);
int i = (int)(Math.random()*900 + 100);
System.out.println(i);
return "TK"+str + i;
}
}
Java中用随机数生成不同订单编号的方法
最新推荐文章于 2023-06-28 15:51:13 发布