java中添加流水单号

 1 //用于生成出库的ID
 2       public static String getexportid(){
 3     //生成规则:Ck+时间戳(20170626143520)+6位的随机数
 4           return "CK"+getnowstr()+getStringRandom(6);
 5       }
 6       public static String getstorageid(){
 7             //生成规则:Rk+时间戳(20170626143520)+6位的随机数
 8                   return "RK"+getnowstr()+getStringRandom(8);
 9               }
10       
11       private static String getnowstr(){
12           Date date = new Date();
13           SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
14           String str = sdf.format(date);
15           return str;
16       }
17       //随机生成六位数
18       private static String getStringRandom(int length) {  
19           
20           String val = "";  
21           Random random = new Random();  
22             
23           //参数length,表示生成几位随机数  
24           for(int i = 0; i < length; i++) {  
25                 
26               String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";  
27               //输出字母还是数字  
28               if( "char".equalsIgnoreCase(charOrNum) ) {  
29                   //输出是大写字母还是小写字母  
30                   int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;  
31                   val += (char)(random.nextInt(26) + temp);  
32               } else if( "num".equalsIgnoreCase(charOrNum) ) {  
33                   val += String.valueOf(random.nextInt(10));  
34               }  
35           }  
36           return val;  
37       }  

 

转载于:https://www.cnblogs.com/gongxuanming/p/7080969.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值