groovy how to get next month from given date
Hi can anybody please help me in this. I want to display all the months from a given specific date.
for Eg: given date i开发者_如何学JAVAs: 15-Mar-2011 Output should be: Mar/2011,Apr/2011 .... Feb/2012
How can i acheive the above in groovy?
You can use Groovy's TimeCategory to write sth. like myDate + 3.months
. The following code creates the list you wanted:
use (groovy.time.TimeCategory) {
Date date = Date.parse("dd-MMM-yyyy", "15-Mar-2011")
def months = (0..11).collect {
(date + it.months).format("MMM/yyyy")
}
}
精彩评论