Reputation: 1153
In Grails, is there a simple way to add/subtract months to/from a date?
We have methods like dateObj.add(10), which would add 10 days to dateObj. So my question is is there a way to add months.
Upvotes: 8
Views: 13865
Reputation: 12334
The TimeCategory
class provides a DSL for time manipulation:
import groovy.time.TimeCategory
use (TimeCategory) {
twoMonthsFromNow = new Date() + 2.month
}
The documentation for TimeCategory
can be found here.
Upvotes: 27
Reputation: 209
You can try :
d = new GregorianCalendar()
d.setTime(new Date())
d.add(Calendar.MONTH,5)
d.getTime()
Upvotes: 5