python用身份证计算年龄

import datetime
national_id = '500222197804127811'
current_day =  datetime.datetime.now()
birth_date = datetime.datetime.strptime(national_id[6:14],'%Y%m%d')
print (current_day - birth_date).days/365

留言

熱門文章