Skip to content

Instantly share code, notes, and snippets.

@Steinblock
Created November 26, 2015 09:52
Show Gist options
  • Save Steinblock/7407f7d2218fc46a7e0d to your computer and use it in GitHub Desktop.
Save Steinblock/7407f7d2218fc46a7e0d to your computer and use it in GitHub Desktop.
DateTimeExtensions
public static class DateTimeExtensions
{
public static DateTime TrimMilliseconds(this DateTime date)
{
return date.AddMilliseconds(-date.Millisecond);
}
}
[TestClass]
public class DateTimeExtensionsTest
{
[TestMethod]
public void CanTrimMilliseconds()
{
var date1 = new DateTime(1,1,1, 1,1,1).AddMilliseconds(1);
var date2 = new DateTime(1, 1, 1, 1, 1, 1).AddMilliseconds(2);
Assert.AreNotEqual(date1, date2);
Assert.AreEqual(date1.TrimMilliseconds(), date2.TrimMilliseconds());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment