本文整理匯總了C#中System.DateTimeOffset.CompareTo方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeOffset.CompareTo方法的具體用法?C# DateTimeOffset.CompareTo怎麽用?C# DateTimeOffset.CompareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.CompareTo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
public class CompareTimes
{
private enum TimeComparison
{
Earlier = -1,
Same = 0,
Later = 1
};
public static void Main()
{
DateTimeOffset firstTime = new DateTimeOffset(2007, 9, 1, 6, 45, 0,
new TimeSpan(-7, 0, 0));
DateTimeOffset secondTime = firstTime;
Console.WriteLine("Comparing {0} and {1}: {2}",
firstTime, secondTime,
(TimeComparison) firstTime.CompareTo(secondTime));
secondTime = new DateTimeOffset(2007, 9, 1, 6, 45, 0,
new TimeSpan(-6, 0, 0));
Console.WriteLine("Comparing {0} and {1}: {2}",
firstTime, secondTime,
(TimeComparison) firstTime.CompareTo(secondTime));
secondTime = new DateTimeOffset(2007, 9, 1, 8, 45, 0,
new TimeSpan(-5, 0, 0));
Console.WriteLine("Comparing {0} and {1}: {2}",
firstTime, secondTime,
(TimeComparison) firstTime.CompareTo(secondTime));
// The example displays the following output to the console:
// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 6:45:00 AM -07:00: Same
// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 6:45:00 AM -06:00: Later
// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 8:45:00 AM -05:00: Same
}
}