groovy 函数计算身份证的性别和年龄

// 根据身份证第17位判断是否为男性(奇男偶女)
def id = "210283190012023736"
def num = Integer.parseInt(id.substring(16,17))
if ( num % 2 == 1) return 1
return 0
// 根据身份证第7-9位,计算今年的年龄
def id = "210283190012023736"
def now = Calendar.getInstance()
return now.get(Calendar.YEAR) - Integer.parseInt(id.substring(6,10))
posted @ 2025-02-18 16:02  miozus  阅读(28)  评论(0)    收藏  举报