如何计算groovy中两个日期之间的总天数

时间:2013-08-19 11:50:06

标签: groovy

如何计算groovy中两个日期之间的总月数和年份

date1 =2012 nov 1
date2 =2013 feb 1

所需的输出是年= 0和月= 3。  任何答案都有帮助

1 个答案:

答案 0 :(得分:0)

我认为应该这样做:

monthBetween = (start[Calendar.MONTH] - end[Calendar.MONTH]) + 1
yearsBetween = start[Calendar.YEAR] - end[Calendar.YEAR]
months = monthBetween + (yearsBetween * 12)

取自Calculate difference in months between two dates with Groovy