//添加引用
using system;
DateTime marriedTime = Convert.ToDateTime("2024-04-01 08:08:08");
DateTime nowTime = DateTime.Now;
TimeSpan timeSpan2 = new TimeSpan(marriedTime.Ticks);
TimeSpan timeSpan1 = new TimeSpan(nowTime.Ticks);
//方式1:计算两个时间差的绝对值
TimeSpan timeSpanSub = timeSpan1.Subtract(timeSpan2).Duration();
//方式1:计算两个时间差的真实值(大于正数,小于负数)
TimeSpan timeSpanSub = nowTime - marriedTime;//
int nDays = timeSpanSub.Days; //差值:天数
int nHours = timeSpanSub.Hours; //差值:小时
int nMinutes = timeSpanSub.Minutes; //差值:分钟