本文整理汇总了C#中System.DateTimeOffset.Subtract方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.Subtract方法的具体用法?C# DateTimeOffset.Subtract怎么用?C# DateTimeOffset.Subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.Subtract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DateTimeOffset
DateTimeOffset firstDate = new DateTimeOffset(2018, 10, 25, 18, 0, 0,
new TimeSpan(-7, 0, 0));
DateTimeOffset secondDate = new DateTimeOffset(2018, 10, 25, 18, 0, 0,
new TimeSpan(-5, 0, 0));
DateTimeOffset thirdDate = new DateTimeOffset(2018, 9, 28, 9, 0, 0,
new TimeSpan(-7, 0, 0));
TimeSpan difference;
difference = firstDate.Subtract(secondDate);
Console.WriteLine($"({firstDate}) - ({secondDate}): {difference.Days} days, {difference.Hours}:{difference.Minutes:d2}");
difference = firstDate.Subtract(thirdDate);
Console.WriteLine($"({firstDate}) - ({thirdDate}): {difference.Days} days, {difference.Hours}:{difference.Minutes:d2}");
输出:
(10/25/2018 6:00:00 PM -07:00) - (10/25/2018 6:00:00 PM -05:00): 0 days, 2:00 (10/25/2018 6:00:00 PM -07:00) - (9/28/2018 9:00:00 AM -07:00): 27 days, 9:00
示例2: DateTimeOffset
DateTimeOffset offsetDate = new DateTimeOffset(2007, 12, 3, 11, 30, 0,
new TimeSpan(-8, 0, 0));
TimeSpan duration = new TimeSpan(7, 18, 0, 0);
Console.WriteLine(offsetDate.Subtract(duration).ToString()); // Displays 11/25/2007 5:30:00 PM -08:00