如何计算出生日期的年龄 [英] how do calculate age from date of birth

查看:80
本文介绍了如何计算出生日期的年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我想根据出生日期计算学生的年龄。年龄应该在下拉列表控件中选择年份时自动计算,并且应该显示在附近的文本框中。如何做这个?

解决方案

这里..

http://stackoverflow.com/questions/14766086/how-to-calculate-age-in-years-from-dob-in- c-sharp [ ^ ]

如何计算使用C#的年龄 [ ^ ]

http://stackoverflow.com/questions/16874911/compute-age-from-given-birthdate [ ^ ]

https://msdn.microsoft.com/en-us/library/aa227466(v = vs.60 ).aspx [ ^ ]

http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c [ ^ ]


解决问题的最简单方法:

首先将下拉列表设置为autopostback并为OnSelectedIndexChanged添加eventhandler

在你的eventhandler中,获取下拉列表的SelectedValue并将其转换为int(year)

然后从DateTime.UtcNow中减去该值,并减去result.Years到txtBox.Text属性。


请参阅此链接,

这里他们使用3个文本框

< a href =http://www.visual-basic-tutorials.com/age-calculator-in-visual-basic.htm> http://www.visual-basic-tutorials.com/age-calculator-in -visual-basic.htm [ ^ ]



这里使用日期字符串,

http://stackoverflow.com/questions/16874911/compute-age-from-given-生日 [ ^ ]

In my project, I want to calculate the age of students by their date of birth.The age should calculate automatically when they select the year in the dropdown list control and it should be displayed in a textbox near that.How to do this?

解决方案

Here..
http://stackoverflow.com/questions/14766086/how-to-calculate-age-in-years-from-dob-in-c-sharp[^]
How to calculate Age using C#[^]
http://stackoverflow.com/questions/16874911/compute-age-from-given-birthdate[^]
https://msdn.microsoft.com/en-us/library/aa227466(v=vs.60).aspx[^]
http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c[^]


Simplest solution to the problem:
First set the dropdownlist to autopostback and add eventhandler for OnSelectedIndexChanged
In your eventhandler, get the SelectedValue of the dropdownlist and convert it to int(year)
Then do subtract the value from DateTime.UtcNow, and subtract the result.Years to the txtBox.Text property.


Refer this link,
Here they are using 3 Textboxes
http://www.visual-basic-tutorials.com/age-calculator-in-visual-basic.htm[^]

and here by using Date String,
http://stackoverflow.com/questions/16874911/compute-age-from-given-birthdate[^]


这篇关于如何计算出生日期的年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆