python中的年龄计算器从日期(mm/dd/yyyy)开始,并仅以年为单位打印年龄

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22344244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:46:07  来源:igfitidea点击:

age calculator in python from date (mm/dd/yyyy) and print age in years only

pythondatecalculator

提问by Jothimani

Hello fiends i want to develop a application, for here i want to know the age calculator in python from date (mm/dd/yyyy) and print age in years only...

你好恶魔我想开发一个应用程序,因为在这里我想知道python中的年龄计算器从日期(mm/dd/yyyy)开始并仅以年为单位打印年龄......

please give me a piece of code

请给我一段代码

thanks

谢谢

import datetime
bday=input("Enter your Birthday as(mm/dd/yyyy): ")
today.today()
age=bday.year-today.year
print"age is :" age

采纳答案by Nilesh

try this

尝试这个

from datetime import datetime

my_date = raw_input("Enter B'date in mmi/dd/yyyy format:")

b_date = datetime.strptime(my_date, '%m/%d/%Y')

print "Age : %d" % ((datetime.today() - b_date).days/365)