I'm new to groovy and I'd like to know how to generate random dates in groovy, in a specific range. Let's say from June 2013 to June 2014.
Thanks
Consider this:
def dateA = Date.parse("dd-MM-yyyy", "01-06-2013")
int range = 365
def randomInterval = new Random().nextInt(range)
def dateB = dateA.plus(randomInterval)
println dateA
println dateB
Note that this does not account for leap years.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With