我有一個擁有人生日期的日期對象。我的代碼如下所示:試圖在groovy中計算年齡
def getAge(){
//birthday, birthYear, birthMonth, birthDayOfMonth are class level properties
def c= new GregorianCalendar(birthYear, birthMonth-1, birthDayOfMonth)
birthday = c.time
//What do I do now?
}
我需要返回此人的年齡。我如何在Groovy中做到這一點?年齡只需要是一個整數。
1;請注意,如果使用舊版本的groovy,則需要將'clearTime()'放在單獨的行上,因爲直到版本1.8左右纔會返回日期對象。 – 2013-11-25 21:12:47