DateTime bday;
TimeSpan xcha;
DateTime now = DateTime.Now;
string dd, hh, mm, ss;
try
{
bday = DateTime.Parse(this.TextBox2.Text);
xcha = now.Subtract(bday); // 用 now -bday 也可以
xcha = xcha.Duration(); //对于时间负情况的时候做处理
this.Label8.Text = xcha.ToString();
}
catch (Exception err)
{
this.Label8.Text = err.ToString();
return;
}
dd = xcha.Days.ToString();
hh = xcha.Hours.ToString();
mm = xcha.Minutes.ToString();
ss = xcha.Seconds.ToString();
this.Label9.Text = "另外一种显示方法:相差" + dd + "天" + hh + "小时" + mm + "分钟" + ss + "秒";
C#日期
最新推荐文章于 2024-09-30 14:15:34 发布