嗨,任何人都可以帮助我.我想显示特定日期的所有月份.
例如:给定日期是:2011年3月15日输出应该是:2011年3月,2011年4月...... 2012年2月
我怎么能在groovy中实现上述目标?
您可以使用Groovy的TimeCategory来编写某些内容.喜欢myDate + 3.months.以下代码创建了您想要的列表:
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")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1442 次 |
| 最近记录: |