c# 生成随机时间
1 Random random = new Random((int)(DateTime.Now.Ticks)); 2 int i = 0; 3 while (i < 100) 4 { 5 int hour = random.Next(2, 5); 6 int minute = random.Next(0, 60); 7 int second = random.Next(0, 60); 8 string tempStr = string.Format("{0} {1}:{2}:{3}", DateTime.Now.ToString("yyyy-MM-dd"), hour, minute, second); 9 DateTime rTime = Convert.ToDateTime(tempStr); 10 Console.WriteLine(rTime.ToString()); 11 i++; 12 } 13 Console.ReadKey();
工欲善其事,必先利其器。