IMO, the best time library in java is JodaTime.
If you want a random TimeStam in 2012, for example, you should start by creating a date 01/01/2012, and then add a random amount of time. Finally, create a TimeStamp object with a long constructor:
org.joda.time.DateTime tempDateTime = org.joda.time.DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime("2012-01-01").plusMillis(my_random_value); return new Timestamp(tempDateTime .getMillis())
jocelyn Jun 13 2018-12-12T00: 00Z
source share