从计算日期年龄文本框在C#

编程入门 行业动态 更新时间:2024-10-27 18:19:04
本文介绍了从计算日期年龄文本框在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#

本文发布于:2023-10-18 11:45:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   年龄   日期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!