日期:2014-05-17 浏览次数:20747 次
//得到d1这个日期这个月的总小时数 DateTime.Now.Subtract( new DateTime(DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.Ticks) ).TotalHours
------解决方案--------------------
DateTime dt1 = new DateTime(2012, 10, 1, 0, 12, 0);// DateTime.Now DateTime dt2 = dt1.AddHours(-2); if (dt2.Year < dt1.Year || dt2.Month < dt1.Month) { dt2 = new DateTime(dt1.Year, dt1.Month, 1); }
------解决方案--------------------
DateTime dt2= dt1.AddHours(-2);
if (dt2.Month < dt1.Month)
{
dt2 =new DateTime(dt1.Year, dt1.Month,1, 0, 0, 0);
}