方法一:
DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd")
方法二:
TimeSpan span = new DateTime(2005,2,11,22,22,44,555) - new DateTime(2004,9,1,1,1,1,1);
int int_day=span.Days;
int int_hour=span.Hours;
int int_min=span.Minutes;
int int_sec=span.Seconds;
int int_millisec=span.Milliseconds;
方法三:
一个日期加上或减去一个值 (比如年份):
DateTime newDate = DateTime.Now.AddYears(2); //加
DateTime newDate = DateTime.Now.AddYears(-2); //减
两个日期相减
DateTime date1 = new DateTime(2007,7,15);
DateTime date2 = DateTime.Now;
TimeSpan ts = date2 - date1;
int iDay= ts.Days;
转载自:http://6377936.blog.163.com/blog/static/392228342009101645146228/