本文整理汇总了C#中LocalDateTime.PlusSeconds方法的典型用法代码示例。如果您正苦于以下问题:C# LocalDateTime.PlusSeconds方法的具体用法?C# LocalDateTime.PlusSeconds怎么用?C# LocalDateTime.PlusSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.PlusSeconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CuriousSubtraction
public void CuriousSubtraction()
{
var shanghai = DateTimeZoneProviders.Tzdb["Asia/Shanghai"];
var localBefore = new LocalDateTime(1900, 12, 31, 23, 54, 16);
var localAfter = localBefore.PlusSeconds(1);
// Note: The behavior of NodaTime's Lenient resolver changed in 2.0, which deviates from the problem described in the original post.
var oldLenientResolver = Resolvers.CreateMappingResolver(Resolvers.ReturnLater, Resolvers.ReturnStartOfIntervalAfter);
var instantBefore = localBefore.InZone(shanghai, oldLenientResolver).ToInstant();
var instantAfter = localAfter.InZone(shanghai, oldLenientResolver).ToInstant();
Assert.AreEqual(Duration.FromSeconds(344), instantAfter - instantBefore);
// Now let's resolve them differently...
var resolver = Resolvers.CreateMappingResolver(Resolvers.ReturnEarlier, Resolvers.ThrowWhenSkipped);
instantBefore = localBefore.InZone(shanghai, resolver).ToInstant();
instantAfter = localAfter.InZone(shanghai, resolver).ToInstant();
Assert.AreEqual(Duration.FromSeconds(1), instantAfter - instantBefore);
}
示例2: Addition_Duration
public void Addition_Duration()
{
const int minutes = 23;
const int hours = 3;
const int milliseconds = 40000;
const long seconds = 321;
const long nanoseconds = 12345;
const long ticks = 5432112345;
// Test all three approaches... not bothering to check a different calendar,
// but we'll use two different offsets.
OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9);
OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1));
Assert.AreEqual(expected, start + duration);
Assert.AreEqual(expected, start.Plus(duration));
Assert.AreEqual(expected, OffsetDateTime.Add(start, duration));
Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours));
Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours));
Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes));
Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes));
Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds));
Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds));
Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds));
Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds));
Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks));
Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks));
Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds));
Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds));
}
示例3: PlusSeconds_Simple
public void PlusSeconds_Simple()
{
LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8);
LocalDateTime expectedForward = new LocalDateTime(2011, 4, 2, 12, 15, 18);
LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 12, 14, 58);
Assert.AreEqual(expectedForward, start.PlusSeconds(10));
Assert.AreEqual(expectedBackward, start.PlusSeconds(-10));
}