Calculate age in Groovy from today -
It is trying to figure out how old someone is based on their beta. The following code gives us the number of days
def now = new date () DEF DOB = new date ('08 / 21/1982 ') println now - dob < / Pre> We can divide by 365 but this is not entirely accurate. There should be an easy way to do this, but I can not find it. any idea? Or using Java 8 and Groovie 2.3 RC (if you want to be on the bleeding edge); -
)
import java.time * Local Date Today = Local Date () Local Day Birthday = Local Date (1982, month, August, 8) period duration = period. Beach (Birthday, Today) Println "" "$ period.years year, | $ period.months month, | $ period.days day" "". StripMargin ()
Comments
Post a Comment