DateTime d1 = hrStaff.DateJoin; DateTime d2 = DateTime.Now; TimeSpan d3 = d2.Subtract(d1); double d4 = (double)(d3.Days) / 365; //int interval = new TimeSpan(d2.Ticks - d1.Ticks).Days; 获取总共相差的天数 string str1 = d4.ToString("f1");//fN 保留N位,四舍五入 //decimal dec = decimal.Round((decimal)(d3.Days) / 365, 1); //同样能实现四舍五入保留一位小数
参考:
http://blog.csdn.net/binzai325/article/details/6908112
http://www.cnblogs.com/sunney/archive/2010/07/28/1786903.html
http://www.zzzj.com/html/20080926/66172.html
http://www.cnblogs.com/sunney/archive/2010/07/28/1786903.html