import java
import java
import java
public class getrandomtiem {
//返回
public static void main(string []args){
simpledateformat format = new simpledateformat(
date randomdate=randomdate(
string randomdats=
system
}
/**
* 獲取隨機日期
* @param begindate 起始日期
* @param enddate 結束日期
* @return
*/
private static date randomdate(string begindate
try {
simpledateformat format = new simpledateformat(
date start = format
date end = format
//gettime()表示返回自
if(start
return null;
}
long date = random(start
return new date(date)
} catch (exception e) {
e
}
return null;
}
private static long random(long begin
long rtn = begin + (long)(math
//如果返回的是開始時間和結束時間
if(rtn == begin || rtn == end){
return random(begin
}
return rtn;
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27118.html