时间:2020-11-04 11:44:03 | 栏目:JAVA代码 | 点击:次
根据起始时间生成随机事件,代码如下:
public static Date randomDate(Date beginDate,Date endDate ){ if(beginDate.getTime() >= endDate.getTime()){ return new Date(); } long date = random(beginDate.getTime(),endDate.getTime()); return new Date(date); } public static long random(long begin,long end){ long rtn = begin + (long)(Math.random() * (end - begin)); if(rtn == begin || rtn == end){ return random(begin,end); } return rtn; }
总结