如何在Windows应用程序中根据日期时间选择器计算年龄? [英] How to calculate age based on datetime picker in windows application?
本文介绍了如何在Windows应用程序中根据日期时间选择器计算年龄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何使用c#编码在Windows应用程序中根据日期时间选择器选择来计算年龄。
< br $>
谢谢和问候,
Murali。
Hi All,
How to calculate age based on "date time picker selection" in windows application with c# coding.
Thanks and Regards,
Murali.
推荐答案
int myAge =
DateTime.Today.Year - dateTimePicker1.Value.Year; // CurrentYear - YourBirthDate
textBox1.Text = myAge.ToString();
您好,
看看这里:
计算年,月,日两个日期之间的持续时间 [ ^ ]
要从DateTimePicker
获取值(DateTime
),请尝试这个:
Hi,
Have a look here:
Calculating Duration Between Two Dates in Years, Months and Days[^]
To get the value (DateTime
) fromDateTimePicker
, try this:
DateTime dt = dateTimePicker1.Value;
试试这个..
Try this..
TimeSpan ts=DateTime.Now - Convert.ToDateTime(datePicker.SelectedDate);
int age = Convert.ToInt32(ts.Days) / 365;
希望这会刺激你。
hope this will heip you.
这篇关于如何在Windows应用程序中根据日期时间选择器计算年龄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文