从计算日期年龄文本框在C# [英] Calculate age from date in textbox in C#
本文介绍了从计算日期年龄文本框在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
计算从生日年龄
块引用>如何计算年龄年,采取从文本框输入格式为
DD / MM / YYYY
?例如
输入:txtDOB.Text 20/02/1989(字符串格式)结果
输出:txtAge.Text 23
块引用>解决方案您可以使用的
。减去
方法的DateTime
(链接),然后使用天
属性来确定实际年龄:现在的DateTime = DateTime.Now;
日期时间givenDate = DateTime.Parse(输入);INT天= now.Subtract(givenDate).Days
INT年龄= Math.Floor(天/ 365.24219)Possible Duplicate:
Calculating age from birthdayHow 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 ofDateTime
(link) and then use theDays
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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文