Calculate # of Years Alive in C# WinForm
This question already has an answer here:
Try something like this:
private void button1_Click(object sender, EventArgs e)
{
DateTime sonsBirthday = DateTime.Parse(txtSonsBirthday.Text).Date;
DateTime now = DateTime.Now;
TimeSpan timeSpan = now - sonsBirthday;
//timeSpan = Convert.TimeSpan(lblTimeAlive); // old
lblTimeAlive.Text = timeSpan.ToString(); // new
Then fine tune the string formatting for timeSpan
.
上一篇: 从C#中的文本框中的日期计算年龄
下一篇: 计算C#WinForm中的活跃年数