本文整理汇总了C#中DateTimeOffset.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.CompareTo方法的具体用法?C# DateTimeOffset.CompareTo怎么用?C# DateTimeOffset.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.CompareTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareTwoDateInDiffTZ
public void CompareTwoDateInDiffTZ ()
{
DateTimeOffset dt1 = new DateTimeOffset (2007, 12, 16, 15, 06, 00, new TimeSpan (1, 0, 0));
DateTimeOffset dt2 = new DateTimeOffset (2007, 12, 16, 9, 06, 00, new TimeSpan (-5, 0, 0));
DateTimeOffset dt3 = new DateTimeOffset (2007, 12, 16, 14, 06, 00, new TimeSpan (1, 0, 0));
object o = dt1;
Assert.IsTrue (dt1.CompareTo (dt2) == 0);
Assert.IsTrue (DateTimeOffset.Compare (dt1, dt2) == 0);
Assert.IsTrue (dt1 == dt2);
Assert.IsTrue (dt1.Equals (dt2));
Assert.IsFalse (dt1 == dt3);
Assert.IsTrue (dt1 != dt3);
Assert.IsFalse (dt1.EqualsExact (dt2));
Assert.IsTrue (dt1.CompareTo (dt3) > 0);
Assert.IsTrue (((IComparable)dt1).CompareTo (o) == 0);
}
示例2: Max
public static DateTimeOffset Max(
DateTimeOffset dateTimeOffset,
DateTimeOffset otherDateTimeOffset) =>
dateTimeOffset.CompareTo(otherDateTimeOffset) >= 0 ? dateTimeOffset : otherDateTimeOffset;
示例3: Compare
public static void Compare(DateTimeOffset dateTimeOffset1, DateTimeOffset dateTimeOffset2, int expected)
{
Assert.Equal(expected, Math.Sign(dateTimeOffset1.CompareTo(dateTimeOffset2)));
Assert.Equal(expected, Math.Sign(DateTimeOffset.Compare(dateTimeOffset1, dateTimeOffset2)));
IComparable comparable = dateTimeOffset1;
Assert.Equal(expected, Math.Sign(comparable.CompareTo(dateTimeOffset2)));
if (expected > 0)
{
Assert.True(dateTimeOffset1 > dateTimeOffset2);
Assert.Equal(expected >= 0, dateTimeOffset1 >= dateTimeOffset2);
Assert.False(dateTimeOffset1 < dateTimeOffset2);
Assert.Equal(expected == 0, dateTimeOffset1 <= dateTimeOffset2);
}
else if (expected < 0)
{
Assert.False(dateTimeOffset1 > dateTimeOffset2);
Assert.Equal(expected == 0, dateTimeOffset1 >= dateTimeOffset2);
Assert.True(dateTimeOffset1 < dateTimeOffset2);
Assert.Equal(expected <= 0, dateTimeOffset1 <= dateTimeOffset2);
}
else if (expected == 0)
{
Assert.False(dateTimeOffset1 > dateTimeOffset2);
Assert.True(dateTimeOffset1 >= dateTimeOffset2);
Assert.False(dateTimeOffset1 < dateTimeOffset2);
Assert.True(dateTimeOffset1 <= dateTimeOffset2);
}
}
示例4: Between
/// <summary>
/// A T extension method that check if the value is between (exclusif) the minValue and maxValue.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <param name="minValue">The minimum value.</param>
/// <param name="maxValue">The maximum value.</param>
/// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns>
/// ###
/// <typeparam name="T">Generic type parameter.</typeparam>
public static bool Between(this DateTimeOffset @this, DateTimeOffset minValue, DateTimeOffset maxValue)
{
return minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1;
}