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;
	}
}

  

posted on 2017-08-11 16:34  ckx0709  阅读(1476)  评论(0编辑  收藏  举报

导航