java 使用UUID生成19随机单号 纯数字,数字+字母唯一不重复单号

/**
 * Created by cc 
 * 生成订单号
 * uuid: db30cc85-3387-4845-87bc-dc390b55b7ea 8+ 201508171108900(yyMMddHHMMSS)
 * 即: db30cc85201508171108900
 */
public class OrderNoUtil {

public static  String getOrderNo(){
    String orderNo = "" ;
 UUID uuid = UUID.randomUUID();
 String trandNo = String.valueOf((Math.random() * 9 + 1) * 1000000);
    String sdf = new SimpleDateFormat("yyyyMMddHHMMSS").format(new Date());
    orderNo = uuid.toString().substring(0, 8);
    orderNo = orderNo + sdf ;
    return orderNo ;
}

//生成19随机单号 纯数字
  public static String getOrderNo(){ String orderNo = "" ; String trandNo = String. valueOf((Math. random() * 9 + 1) * 1000000) ; String sdf = new SimpleDateFormat( "yyyyMMddHHMMSS").format( new Date()) ; orderNo = trandNo.toString().substring( 0 , 4) ; orderNo = orderNo + sdf ; return orderNo ; }}

你可能感兴趣的:(web后端开发)