I have recently started learning Grails and Groovy and have stuck a lot in generating a date in a certain range .
I can make a date based on the difference of one year. But how do I add a month and date?
This is what I got, Dates Utilities
DateUtils.addYears (new date), - (18+ new random (.nextInt (20)))
It works to generate a date based on year. But I have to do the same month every month. How to add one month to this month, I can also make random this month
The second to do so Method:
Date Random Date (range & lt; date & gt; range) {range.from + new random () NextInt (range.to - range.from + 1)}
Then, you can do this:
def start = date.parse (' Defy end = Date.parse ('Yyyy-MM-dd', '2015-01-10') println randomDate (start..end)
No comments:
Post a Comment