asp.net - How to get random time in certain time format -
i want date 2013/01/01 today. plus time 14:00 23:00 time interval 15min.
for example:
2013/01/01 14:15 2013/01/21 14:30 2013/01/21 17:45 2013/03/17 14:00 . . .
for date, can use code below i'm not sure of time part
datetime start = new datetime(2013, 1, 1); random gen = new random(); int range = (datetime.today - start).days; start.adddays(gen.next(range));
this should work:
int starthour = 14; int endhour = 23; int allquarters = enumerable.range(0, (endhour - starthour) * 4).count(); timespan time = timespan.fromminutes(gen.next(allquarters) * 15); start = start + timespan.fromhours(starthour) + time;
Comments
Post a Comment