Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何计算groovy中两个日期之间的总月数和年数
date1 =2012 nov 1 date2 =2013 feb 1
所需的输出是年 = 0 和月 = 3。任何答案都有帮助
我认为这应该这样做:
monthBetween = (start[Calendar.MONTH] - end[Calendar.MONTH]) + 1 yearsBetween = start[Calendar.YEAR] - end[Calendar.YEAR] months = monthBetween + (yearsBetween * 12)
取自使用 Groovy 计算两个日期之间的月差