Here you can find the source of generateRandomDateTimeForLogEvent(Date laterThan)
public static Date generateRandomDateTimeForLogEvent(Date laterThan)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import java.util.concurrent.TimeUnit; public class Main { public static Date generateRandomDateTimeForLogEvent(Date laterThan) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); if (laterThan == null) { cal.add(GregorianCalendar.YEAR, -1); cal.add(GregorianCalendar.MONTH, (int) (Math.round(Math.random() * 12)) * -1); cal.add(GregorianCalendar.WEEK_OF_MONTH, (int) (Math.round(Math.random() * 4)) * -1); cal.add(GregorianCalendar.DAY_OF_WEEK, (int) (Math.round(Math.random() * 7)) * -1); laterThan = cal.getTime();/*from www .ja v a2 s. c o m*/ } long randomAdditionalTime = (long) (Math.round(Math.random() * TimeUnit.DAYS.toMillis(1))); cal.setTimeInMillis(laterThan.getTime() + randomAdditionalTime); return cal.getTime(); } }