开发者

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") 
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜