I have a "requirement" to give a timestamp to the nearest second... but NOT more accurate than that. Rounding or truncating the time is fine.
I have come up with this abomination
dateTime = DateTime.Parse(DateTime.UtcNow.ToString("U"));
(U is the Long format date and time. "03 January 2007 17:25:30")
Is there some less horrific way of achieving this?
Edit: So from the linked truncate milliseconds answer (thanks John Odom) I am going to do this
private static DateTime GetCurrentDateTimeNoMilliseconds()
{
var currentTime = DateTime.UtcNow;
return new DateTime(currentTime.Ticks - (currentTime.Ticks % TimeSpan.TicksPerSecond), currentTime.Kind);
}
barely less horrific.. but it does preserve the 'kind' of datetime which I do care about. My solution did not.