import datetime
ID=str(input("輸入身份證號碼"))
birthday_year=ID[6:10]
birthday_month=ID[10:12]
birthday_day=ID[12:14]
print("{0}年{1}月{2}日".format(birthday_year,birthday_month,birthday_day))
Now_Time=datetime.datetime.today()
#獲取今日日期
today=int(str(Now_Time.month)+str(Now_Time.day))
if Now_Time.day<10:
today=int(str(Now_Time.month)+"0"+str(Now_Time.day))
#如果今日日期超過生日 則年齡為年份相減,否則年份相減再減1
if today-int(birthday_month+birthday_day)>=0:
age=Now_Time.year-int(birthday_year)
else:
age=Now_Time.year-int(birthday_year)-1
print("年齡:",age)
import datetime
ID=str(input("輸入身份證號碼"))
birthday_year=ID[6:10]
birthday_month=ID[10:12]
birthday_day=ID[12:14]
print("{0}年{1}月{2}日".format(birthday_year,birthday_month,birthday_day))
Now_Time=datetime.datetime.today()
#獲取今日日期
today=int(str(Now_Time.month)+str(Now_Time.day))
if Now_Time.day<10:
today=int(str(Now_Time.month)+"0"+str(Now_Time.day))
#如果今日日期超過生日 則年齡為年份相減,否則年份相減再減1
if today-int(birthday_month+birthday_day)>=0:
age=Now_Time.year-int(birthday_year)
else:
age=Now_Time.year-int(birthday_year)-1
print("年齡:",age)