本文整理汇总了C#中DateTimeOffset.Between方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.Between方法的具体用法?C# DateTimeOffset.Between怎么用?C# DateTimeOffset.Between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.Between方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Between
public void Between()
{
var date = new DateTimeOffset(2015, 8, 7, 13, 26, 30, TimeSpan.Zero);
Assert.IsTrue(date.Between(date.AddMonths(-3), date.AddMonths(3)));
Assert.IsTrue(date.AddHours(36).Between(date.AddMonths(-3), date.AddMonths(3)));
Assert.IsFalse(date.AddMonths(6).Between(date.AddMonths(-3), date.AddMonths(3)));
Assert.IsFalse(date.AddHours(-2).Between(date, date.AddMonths(3)));
Assert.IsTrue(date.Between(date.AddMonths(-3), date.AddMonths(3), false));
Assert.IsTrue(date.AddHours(36).Between(date.AddMonths(-3), date.AddMonths(3), false));
Assert.IsFalse(date.AddMonths(6).Between(date.AddMonths(-3), date.AddMonths(3), false));
Assert.IsTrue(date.AddHours(-2).Between(date, date.AddMonths(3), false));
Assert.IsFalse(date.AddHours(-24).Between(date, date.AddMonths(3), false));
}
示例2: CheckValidityAt
void CheckValidityAt(DateTimeOffset usedOn)
{
if (!usedOn.Between(IssuedOn, ExpiresOn))
throw new Exception("Invalid credit card.");
}