Java生成随机日期
http://blog.csdn.net/opnmzxcvb/article/details/3970683
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Java代码 public static Date getRandomDate() { Random rand = new Random(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd "); Calendar cal = Calendar.getInstance(); cal.set(2000, 0, 1); long start = cal.getTimeInMillis(); cal.set(2012, 10, 1); long end = cal.getTimeInMillis(); Date d = new Date(start + (long) (rand.nextDouble() * (end - start))); System.out.println(format.format(d)); return d; } |
Date d = new Date(start + (long) (rand.nextDouble() * (end – start)));
这个是从网上见到的 这句有问题 但还没时间去改
