获取当前时间
DateTime nowtime= DateTime.Now;
获取整点方法一
string datehour = nowtime.ToString("yyyy/MM/dd HH:00:00");
string datehourbefore = nowtime.AddHours(-1).ToString("yyyy/MM/dd HH:00:00");
获取整点方法二
string nowtimehour = nowtime.ToString("HH");//当前时间的小时
string nowtimeday = nowtime.ToString("yyyy/MM/dd");//当前时间日期
DateTime nowtimelast = DateTime.Parse(nowtimeday + ' ' + nowtimehour + ':' + "00" + ':' + "00");//转换成当前时间所在的小时
DateTime nowtimebefore = nowtimelast.AddHours(-1);//转换成当前时间所在的上一个小时整点时间
Console.Write("{0}--{1} ", nowtimelast, nowtimebefore);