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.
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.
You can try :
d = new GregorianCalendar()
d.setTime(new Date())
d.add(Calendar.MONTH,5)
d.getTime()
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