0
点赞
收藏
分享

微信扫一扫

java 生成不重复的随机数

import java.text.SimpleDateFormat;
import java.util.Date;public class Test2 {
	public static void main(String[] args){
		SimpleDateFormat formatter2 = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
		SimpleDateFormat formatter = new SimpleDateFormat ("MMddHHmmss");
		Date curDate = new Date(System.currentTimeMillis());//获取当前时间
		String str = formatter.format(curDate);
		String cur = str.substring(0,2);
		String cur2 = str.substring(2,4);
		String temp = (Integer.parseInt(cur)+Integer.parseInt(cur2))+""+str.substring(4);
		int cur_id = Integer.parseInt(temp.substring(0,4))+Integer.parseInt(temp.substring(4));
		System.out.println(cur_id);
	}}

举报

相关推荐

0 条评论