可能重复:
如何在java中将当前日期转换为字符串?
如何以格式返回日期dd/mm/yyyy
?在
package random01;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class Random01 {
public static void main(String[] args) throws ParseException {
Random random = new Random();
String[] v = new String[5];
for (int i = 0;
i < v.length;
i++) {
//long tempo = (long) (1293861598 + random.nextDouble() * 60 * 60 * 24 * 365);
DateFormat dateFormat = new SimpleDateFormat("yyyy");
Date dateFrom = dateFormat.parse("2012");
long timestampFrom = dateFrom.getTime();
Date dateTo = dateFormat.parse("2013");
long timestampTo = dateTo.getTime();
long timeRange = timestampTo - timestampFrom;
long randomTimestamp = timestampFrom + (long) (random.nextDouble() * timeRange);
System.out.println(randomTimestamp);
}
}
}
我需要,例如,2012 年 2 月 11 日