本文介绍了从计算日期年龄文本框在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果 计算从生日年龄
如何计算年龄年,采取从文本框输入格式为 DD / MM / YYYY ?
例如
输入:txtDOB.Text 20/02/1989(字符串格式)结果 输出:txtAge.Text 23
解决方案您可以使用的。减去方法的DateTime (链接),然后使用天属性来确定实际年龄:
现在的DateTime = DateTime.Now;日期时间givenDate = DateTime.Parse(输入);INT天= now.Subtract(givenDate).DaysINT年龄= Math.Floor(天/ 365.24219)Possible Duplicate: Calculating age from birthday
How do you calculate age in years, taking input from TextBox in the format dd/MM/yyyy?
e.g.
input: txtDOB.Text 20/02/1989 (String format) output: txtAge.Text 23
解决方案
You can use the Substract method of DateTime (link) and then use the Days property to determine the actual age:
DateTime now = DateTime.Now; DateTime givenDate = DateTime.Parse(input); int days = now.Subtract(givenDate).Days int age = Math.Floor(days / 365.24219)
更多推荐
从计算日期年龄文本框在C#
发布评论