zoukankan      html  css  js  c++  java
  • 30位以内随机产生时间戳加随机数id

    package com.zx.ps.web.gzdb;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class ckxTest {
    	
    	public static void main(String[] args) {
    		ckxTest ck = new ckxTest();
    		for (int i = 0; i < 100; i++) {
    			String id = ck.creatid(30);
    			System.out.println(id);
    		}
    	}
    	
    	public String creatid(int endIndex){
    		String id="";  
            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");  
            String tc = sf.format(new Date());  
            double du = Math.random();
            String random = String.valueOf(du);
            random = random.length()<18?random+"000":random;
            String sj = random.substring(2, 18);
            id=(tc+sj).substring(0, endIndex); 
    		return id;
    	}
    }
    

      

  • 相关阅读:
    杭电1058
    动态规划之背包模版
    按字典序依次打印只由1~n组成的n位数
    杭电1029
    杭电1257
    杭电2191
    杭电1114
    杭电2602
    南阳975
    杭电2138
  • 原文地址:https://www.cnblogs.com/ckxlovejava/p/7346639.html
Copyright © 2011-2022 走看看