实现效果:
关键知识:(注意:引用 using Microsoft.VisualBasic;)
DateAndTime类的DateDiff静态方法获取日期时间的间隔数:
DateDiff(DateInterval Internal,DateTime Date1,DateTime date2,FirstDayOfWeek DayOfWeek,FirstWeekOfYear WeekOfYear);
实现代码:
private void button1_Click(object sender, EventArgs e) { long age = DateAndTime.DateDiff(DateInterval.Year, //计算年龄 dateTimePicker1.Value, DateTime.Now, FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1); MessageBox.Show("年龄:"+age); //输出年龄 }
原文地址:https://www.cnblogs.com/feiyucha/p/9912156.html
时间: 2024-10-16 20:09:05