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

  

原文地址:https://www.cnblogs.com/ckxlovejava/p/7346639.html