书单推荐:成为Java顶级程序员架构师 ,这20来本(高薪)必看点击获取
java;toolbar:false">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; }
转载请注明:谷谷点程序 » java 根据起始时间生成随机时间