当前位置: 首页>>代码示例>>C#>>正文


C# DateTimeOffset.CompareTo方法代码示例

本文整理汇总了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);
		}
开发者ID:frje,项目名称:SharpLang,代码行数:16,代码来源:DateTimeOffsetTest.cs

示例2: Max

 public static DateTimeOffset Max(
     DateTimeOffset dateTimeOffset,
     DateTimeOffset otherDateTimeOffset) =>
         dateTimeOffset.CompareTo(otherDateTimeOffset) >= 0 ? dateTimeOffset : otherDateTimeOffset;
开发者ID:KimberlyPhan,项目名称:Its.Cqrs,代码行数:4,代码来源:DateTimeOffsetExtensions.cs

示例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);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:30,代码来源:DateTimeOffsetTests.cs

示例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;
 }
开发者ID:Nucs,项目名称:nlib,代码行数:13,代码来源:DateTimeOffset.Between.cs


注:本文中的DateTimeOffset.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。