2 Yukarıda belirtilen çözümler için genişletme yöntemleri
public static bool LiesAfterIgnoringMilliseconds(this DateTime theDate, DateTime compareDate, DateTimeKind kind)
{
DateTime thisDate = new DateTime(theDate.Year, theDate.Month, theDate.Day, theDate.Hour, theDate.Minute, theDate.Second, kind);
compareDate = new DateTime(compareDate.Year, compareDate.Month, compareDate.Day, compareDate.Hour, compareDate.Minute, compareDate.Second, kind);
return thisDate > compareDate;
}
public static bool LiesAfterOrEqualsIgnoringMilliseconds(this DateTime theDate, DateTime compareDate, DateTimeKind kind)
{
DateTime thisDate = new DateTime(theDate.Year, theDate.Month, theDate.Day, theDate.Hour, theDate.Minute, theDate.Second, kind);
compareDate = new DateTime(compareDate.Year, compareDate.Month, compareDate.Day, compareDate.Hour, compareDate.Minute, compareDate.Second, kind);
return thisDate >= compareDate;
}
kullanımı:
bool liesAfter = myObject.DateProperty.LiesAfterOrEqualsIgnoringMilliseconds(startDateTime, DateTimeKind.Utc);
stringgösteriminden nasıl çıkarılacağını veya kaldırılacağınıDateTimeaçıkladığından, "kısaltmayı" netleştirmek için belki de bir düzenleme gereklidir / "damla" milisaniye anlamına gelir "bir üretmekDateTimetüm tarih / saat bileşenleri hariç aynıdır değeriTimeOfDay.TotalMillisecondsolduğunu0." İnsanlar elbette okumuyorlar, ama sadece belirsizlikleri ortadan kaldırmak için.