Just subtract the millisecond part:
DateTime myTime = DateTime.Now.TimeOfDay; myTime = myTime.AddMilliseconds(-myTime.Millisecond);
This can be done in less code without first assigning myTime :
DateTime myTime = DateTime.Now.TimeOfDay.AddMilliseconds( -DateTime.Now.TimeOfDay.Millisecond);
Although somewhat elegant, this is a bad idea. When accessing TimeOfDay twice, there is a chance that it will at some point pass another millisecond before the second access. In this case, the result will not be zero milliseconds.
Anders abel
source share