c# 生成随机时间的小例子
程序员文章站
2023-12-20 17:07:34
复制代码 代码如下:random random = new random((int)(datetime.now.ticks)); &nbs...
复制代码 代码如下:
random random = new random((int)(datetime.now.ticks));
int i = 0;
while (i < 100)
{
int hour = random.next(2, 5);
int minute = random.next(0, 60);
int second = random.next(0, 60);
string tempstr = string.format("{0} {1}:{2}:{3}", datetime.now.tostring("yyyy-mm-dd"), hour, minute, second);
datetime rtime = convert.todatetime(tempstr);
console.writeline(rtime.tostring());
i++;
}
console.readkey();